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

查看生态总览
Skip to content

Accordion ​

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="accordion": root · item · item-separator · 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-accordion>
Vue componentsXhAccordionContent XhAccordionHeader XhAccordionIndicator XhAccordionItem XhAccordionItemSeparator XhAccordionRoot XhAccordionTrigger
ComposableuseAccordion
State machineaccordionMachine
Skin@xihan-ui/styles/accordion.css

Props ​

PropTypeRequired
collectionAccordionNode[]
valuestring[]
defaultValuestring[]
multipleboolean
collapsibleboolean
loopboolean
disabledboolean
variantControlVariant
orientationOrientation
dirDirection
toneTone
sizeSize
lazyMountboolean
unmountOnExitboolean
contentRole'region' | 'group'
onValueChange(details: AccordionValueChangeDetails) => void

AccordionNode ​

Elements of collection.

FieldTypeRequired
valuestringYes
labelstring
contentstring
disabledboolean

Events ​

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

EventPayload
value-changeAccordionValueChangeDetails

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
XhAccordionItemvaluestringYes
XhAccordionItemdisabledboolean
XhAccordionRootrenderContent(node: AccordionNodeMeta) => ReactNode
XhAccordionRootchildrenReactNode

State ​

Public state is written to data-state.

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

The following names are internal to the state machine.

States: idle

Events: ITEM.TOGGLE · VALUE.SET · PRESS.START · PRESS.END

Guards: canPress

connect API ​

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

MemberType
valuestring[]
collectionreadonly AccordionNodeMeta[]
setValue(next: string[]) => void
isOpen(value: string) => boolean
getRootProps() => T['element']
getItemProps(props: AccordionItemProps) => T['element']
getItemSeparatorProps() => T['element']
getHeaderProps(props: AccordionItemProps) => T['element']
getTriggerProps(props: AccordionItemProps) => T['button']
getContentProps(props: AccordionItemProps) => T['element']
getIndicatorProps(props: AccordionItemProps) => T['element']
isContentMounted(props: AccordionItemProps, 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 / Enteraccordion.kbd.toggle
ArrowDown / ArrowRightaccordion.kbd.next
ArrowUp / ArrowLeftaccordion.kbd.prev
Homeaccordion.kbd.first
Endaccordion.kbd.last
Tab / Shift+Tabaccordion.kbd.tab
Enter / Spaceaccordion.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
item-separatoraria-hidden'true'
headeraria-level3
headerrole'heading'
triggeraria-controlsid of the content part
triggeraria-disabled'true' | 'false'
triggeraria-expanded'true' | 'false'
contentaria-labelledbyid of the trigger part
contentroleprops.contentRole
indicatoraria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/accordion.css is written against [data-scope="accordion"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-accordion 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-orientationprops.orientation
rootdata-sizeprops.size
rootdata-toneprops.tone
rootdata-variantprops.variant
itemdata-disabled'' (present only while the condition holds)
itemdata-state'open' | 'closed'
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''
contentdata-state'open' | 'closed'
indicatordata-disabled'' (present only while the condition holds)
indicatordata-instant''
indicatordata-state'open' | 'closed'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-accordion-borderrootbordervariant=outline--xh-border-default
--xh-accordion-content-bgcontentbackgrounddefaulttransparent
--xh-accordion-content-bordercontentbox-shadowdefaulttransparent
--xh-accordion-content-fgcontentcolordefault--xh-fg-muted
--xh-accordion-content-font-sizecontentfont-sizedefault--xh-text-body-size
--xh-accordion-content-pbcontentpadding-block-end@keyframes xh-disclosure-collapse
@keyframes xh-disclosure-expand
default
--xh-_accordion-content-pb
--xh-accordion-content-ptcontentpadding-block-start@keyframes xh-disclosure-collapse
@keyframes xh-disclosure-expand
default
--xh-_accordion-content-pt
--xh-accordion-content-pxcontentpadding-inlinedefault--xh-_accordion-content-px
--xh-accordion-icon-sizeroot
trigger
--xh-icon-sizedefault--xh-glyph-size-md
--xh-glyph-size-sm
--xh-accordion-indicator-fgindicatorcolordefault--xh-fg-subtle
--xh-accordion-item-bgrootbackgroundvariant=outline
variant=subtle
--xh-bg-subtle
--xh-bg-surface
--xh-accordion-item-borderitem
item-separator
root
background
border-block-start
border-inline-start
default
is([data-variant='outline'], [data-variant='subtle'])
not(:last-child)
orientation=horizontal
variant=outline
variant=subtle
--xh-border-subtle
--xh-accordion-item-radiusrootborder-radiusvariant=outline
variant=subtle
--xh-shape-surface
--xh-accordion-item-shadowrootbox-shadowvariant=outline
variant=subtle
none
--xh-accordion-trigger-bgtrigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-accordion-trigger-bg-hovertriggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-accordion-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-accordion-trigger-fg-disabledtriggercolordisabled--xh-_action-variant-fg-disabled
--xh-accordion-trigger-fg-opentriggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=open
--xh-_accordion-open-fg
--xh-accordion-trigger-font-sizetriggerfont-sizedefault--xh-_action-profile-font-size
--xh-accordion-trigger-font-weighttriggerfont-weightdefault
state=open
--xh-text-label-weight
--xh-accordion-trigger-font-weight-opentriggerfont-weightstate=open--xh-accordion-trigger-font-weight
--xh-accordion-trigger-gaptriggergapdefault--xh-_accordion-indicator-gap
--xh-accordion-trigger-htriggerblock-size
min-block-size
default
xh-action-profile=disclosure-trigger
--xh-_action-profile-visual-size
--xh-accordion-trigger-pxtriggerpadding-inlinedefault--xh-_accordion-trigger-px
--xh-accordion-trigger-pytriggerpadding-blockxh-action-profile=disclosure-trigger--xh-_accordion-trigger-py
--xh-accordion-trigger-radiustriggerborder-radiusdefault--xh-_accordion-trigger-radius

Released under The MIT License