生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

Truncate ​

General component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="truncate": root · trigger

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-truncate>
Vue componentsXhTruncate
ComposableuseTruncate
State machinetruncateMachine
Skin@xihan-ui/styles/truncate.css

Props ​

PropTypeRequired
linesnumber
positionTruncatePosition
expandableboolean
openboolean
defaultOpenboolean
tooltipboolean
onOpenChange(details: TruncateOpenChangeDetails) => void
onOverflowChange(details: TruncateOverflowChangeDetails) => void
translationsPartial<TruncateTranslations>

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
open-changeTruncateOpenChangeDetails
overflow-changeTruncateOverflowChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhTruncatedefaultTruncateSlotProps
XhTruncatetriggerTruncateTriggerSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhTruncatetriggerSlotChildren<TruncateTriggerSlotProps>
XhTruncatechildrenSlotChildren<TruncateSlotProps>

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed' | undefined
trigger'open' | 'closed'

The following names are internal to the state machine.

States: closed · open

Events: MEASURE · TOGGLE · CONTROLLED.OPEN · CONTROLLED.CLOSE

Guards: isOpenControlled

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
openboolean
overflowingboolean
setOpen(next: boolean) => void
measure() => void
triggerLabelstring
getRootProps() => T['element']
getTriggerProps() => T['button']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Enter / Spacetruncate.kbd.toggle
Tab / Shift+Tabtruncate.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the root part
triggeraria-expanded'true' | 'false'

Style reference ​

Skin ​

@xihan-ui/styles/truncate.css is written against [data-scope="truncate"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-truncate in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-expandable'' (present only while the condition holds)
rootdata-linesString(lines)
rootdata-middle-textcontext.get('text') | undefined
rootdata-multiline'' (present only while the condition holds)
rootdata-overflowing'' (present only while the condition holds)
rootdata-position'middle' | undefined
rootdata-state'open' | 'closed' | undefined
triggerdata-state'open' | 'closed'
triggerdata-xh-action-control''
triggerdata-xh-action-display'always'
triggerdata-xh-action-profile'text'
triggerdata-xh-action-size'sm'
triggerdata-xh-action-variant'ghost'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-truncate-linesroot-webkit-line-clampmultiline--xh-_truncate-lines

Released under The MIT License