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

查看生态总览
Skip to content

Collapsible ​

Data display 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="collapsible": root · header · trigger · content · indicator

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-collapsible>
Vue componentsXhCollapsibleContent XhCollapsibleHeader XhCollapsibleIndicator XhCollapsibleRoot XhCollapsibleTrigger
ComposableuseCollapsible
State machinecollapsibleMachine
Skin@xihan-ui/styles/collapsible.css

Props ​

PropTypeRequired
openboolean
defaultOpenboolean
disabledboolean
toneTone
sizeSize
dirDirection
lazyMountboolean
unmountOnExitboolean
onOpenChange(details: CollapsibleOpenChangeDetails) => void

Events ​

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

EventPayload
open-changeCollapsibleOpenChangeDetails

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
XhCollapsibleRootchildrenReactNode

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
header'open' | 'closed'
trigger'open' | 'closed'
content'open' | 'closed'
indicator'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · CLOSE · TOGGLE · CONTROLLED.OPEN · CONTROLLED.CLOSE · PRESS.START · PRESS.END

Guards: isOpenControlled · canPress

connect API ​

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

MemberType
openboolean
setOpen(next: boolean) => void
getRootProps() => T['element']
getHeaderProps() => T['element']
getTriggerProps() => T['button']
getContentProps() => T['element']
getIndicatorProps() => T['element']
isContentMounted(present: boolean) => boolean

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
Space / Entercollapsible.kbd.toggle
Enter / Spacecollapsible.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the content part
triggeraria-expanded'true' | 'false'
indicatoraria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/collapsible.css is written against [data-scope="collapsible"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-collapsible in place of data-scope (same specificity) and sits in the xihan.components and xihan.motion layers. 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-disabled'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
headerdata-disabled'' (present only while the condition holds)
headerdata-state'open' | 'closed'
triggerdata-disabled'' (present only while the condition holds)
triggerdata-pressed'' (present only while the condition holds)
triggerdata-state'open' | 'closed'
triggerdata-xh-action-control''
triggerdata-xh-action-display'always'
triggerdata-xh-action-profile'disclosure-trigger'
triggerdata-xh-action-sizeprops.size
triggerdata-xh-action-variant'ghost'
contentdata-instant'' (present only while the condition holds)
contentdata-state'open' | 'closed'
indicatordata-disabled'' (present only while the condition holds)
indicatordata-instant'' (present only while the condition holds)
indicatordata-state'open' | 'closed'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-collapsible-content-fgcontentcolordefault--xh-fg-muted
--xh-collapsible-content-font-sizecontentfont-sizedefault--xh-text-body-size
--xh-collapsible-content-pbcontentpadding-block-end@keyframes xh-disclosure-collapse
@keyframes xh-disclosure-expand
default
--xh-_collapsible-content-pb
--xh-collapsible-content-ptcontentpadding-block-start@keyframes xh-disclosure-collapse
@keyframes xh-disclosure-expand
default
--xh-_collapsible-content-pt
--xh-collapsible-content-pxcontentpadding-inlinedefault--xh-_collapsible-content-px
--xh-collapsible-header-gapheadergapdefault--xh-_collapsible-trigger-gap
--xh-collapsible-icon-sizeroot
trigger
--xh-icon-sizedefault--xh-glyph-size-md
--xh-glyph-size-sm
--xh-collapsible-indicator-fgindicatorcolordefault--xh-fg-subtle
--xh-collapsible-trigger-bgtrigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-collapsible-trigger-bg-hovertriggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-collapsible-trigger-fgtriggercolordefault
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-collapsible-trigger-fg-disabledtriggercolordisabled--xh-_action-variant-fg-disabled
--xh-collapsible-trigger-fg-opentriggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=open
--xh-_collapsible-open-fg
--xh-collapsible-trigger-font-sizetriggerfont-sizedefault--xh-_action-profile-font-size
--xh-collapsible-trigger-font-weighttriggerfont-weightdefault
state=open
--xh-text-label-weight
--xh-collapsible-trigger-font-weight-opentriggerfont-weightstate=open--xh-collapsible-trigger-font-weight
--xh-collapsible-trigger-gaptriggergapdefault--xh-_collapsible-indicator-gap
--xh-collapsible-trigger-htriggerblock-size
min-block-size
default
xh-action-profile=disclosure-trigger
--xh-_action-profile-visual-size
--xh-collapsible-trigger-pxtriggerpadding-inlinedefault--xh-_collapsible-trigger-px
--xh-collapsible-trigger-pytriggerpadding-blockxh-action-profile=disclosure-trigger--xh-_collapsible-trigger-py
--xh-collapsible-trigger-radiustriggerborder-radiusdefault--xh-_collapsible-trigger-radius

Released under The MIT License