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

查看生态总览
Skip to content

Drawer ​

Overlays 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="drawer": root · trigger · backdrop · positioner · content · header · title · description · body · footer · confirm-trigger · cancel-trigger · close-trigger · resize-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-drawer>
Vue componentsXhDrawerBody XhDrawerCancelTrigger XhDrawerCloseTrigger XhDrawerConfirmTrigger XhDrawerContent XhDrawerDescription XhDrawerFooter XhDrawerHeader XhDrawerResizeTrigger XhDrawerRoot XhDrawerTitle XhDrawerTrigger
ComposableuseDrawer
State machinedrawerMachine
Skin@xihan-ui/styles/drawer.css

Props ​

PropTypeRequired
openboolean
defaultOpenboolean
modalboolean
containedboolean
sideDrawerSide
role'dialog' | 'alertdialog'
closeOnEscapeboolean
closeOnInteractOutsideboolean
restoreFocusboolean
sizeSize
variantOverlayBackdropVariant
unmountOnExitboolean
partsTitleDescriptionParts
translationsPartial<DrawerTranslations>
onOpenChange(details: DrawerOpenChangeDetails) => void
onExitComplete() => void
resizableboolean
panelSizenumber
defaultPanelSizenumber
minPanelSizenumber
maxPanelSizenumber
onPanelSizeChange(details: DrawerPanelSizeChangeDetails) => void

Events ​

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

EventPayload
confirmCustomEvent
confirm-errorCustomEvent
cancel-pressCustomEvent
exit-completeCustomEvent
panel-size-changeCustomEvent
open-changeDrawerOpenChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhDrawerRootdefaultDrawerRootSlotProps
XhDrawerRoottrigger—
XhDrawerRoottitle—
XhDrawerRootdescription—
XhDrawerRootbody—
XhDrawerRootfooter—

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
XhDrawerRootcontainer() => Element | null
XhDrawerRoottriggerReactNode
XhDrawerRoottitleReactNode
XhDrawerRootdescriptionReactNode
XhDrawerRootbodyReactNode
XhDrawerRootfooterReactNode
XhDrawerRootactionsDrawerStructureActions
XhDrawerRootconfirmTextstring
XhDrawerRootcancelTextstring
XhDrawerRootonConfirmDrawerActionIntents['onConfirm']
XhDrawerRootonConfirmErrorDrawerActionIntents['onConfirmError']
XhDrawerRootonCancelPressDrawerActionIntents['onCancelPress']
XhDrawerRootchildrenSlotChildren<DrawerRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
trigger'open' | 'closed'
backdrop'open' | 'closed'
positioner'open' | 'closed'
content'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: RESIZE.START · RESIZE.NUDGE · RESIZE.TO_BOUND · RESIZE.MEASURE

Guards: canResize

connect API ​

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

MemberType
openboolean
panelSizenumber | null
resizingboolean
sideDrawerSide
pendingboolean
actionErrorDrawerConfirmErrorDetails | null
setOpen(next: boolean) => void
confirm() => void
cancel() => void
getRootProps() => T['element']
getTriggerProps() => T['button']
getBackdropProps() => T['element']
getPositionerProps() => T['element']
getContentProps() => T['element']
getHeaderProps() => T['element']
getTitleProps() => T['element']
getDescriptionProps() => T['element']
getBodyProps() => T['element']
getFooterProps() => T['element']
getConfirmTriggerProps() => T['button']
getCancelTriggerProps() => T['button']
getCloseTriggerProps() => T['button']
getResizeTriggerProps() => 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
Enter / Spacedrawer.kbd.open-on-trigger
Escapedrawer.kbd.escape
Tabdrawer.kbd.tab
Shift+Tabdrawer.kbd.shift-tab
Enter / Spacedrawer.kbd.press
ArrowLeft / ArrowRight / ArrowUp / ArrowDowndrawer.kbd.resize-step
Shift+ArrowLeft / Shift+ArrowRight / Shift+ArrowUp / Shift+ArrowDowndrawer.kbd.resize-large
Home / Enddrawer.kbd.resize-bound

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the content part
triggeraria-expanded'true' | 'false'
triggeraria-haspopup'dialog'
contentaria-describedbyid of the description part | undefined
contentaria-hidden!open || undefined
contentaria-labelledbyid of the title part | undefined
contentaria-modal'true' | 'false'
contentroleprops.role
confirm-triggeraria-busy'true' | undefined
confirm-triggeraria-disabled'true' | undefined
close-triggeraria-labeltranslations.close
resize-triggeraria-controlsid of the content part
resize-triggeraria-labeltranslations.resizeTrigger
resize-triggeraria-orientation'vertical' | 'horizontal'
resize-triggeraria-valuemaxString(max) | undefined
resize-triggeraria-valueminString(min)
resize-triggeraria-valuenowString(now) | undefined
resize-triggerrole'separator'

Style reference ​

Skin ​

@xihan-ui/styles/drawer.css is written against [data-scope="drawer"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-drawer 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-contained'' (present only while the condition holds)
rootdata-sideprops.side
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
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'text'
triggerdata-xh-action-size'md'
triggerdata-xh-action-variant'outline'
backdropdata-contained'' (present only while the condition holds)
backdropdata-instant'' (present only while the condition holds)
backdropdata-state'open' | 'closed'
backdropdata-variantprops.variant
positionerdata-contained'' (present only while the condition holds)
positionerdata-positioned''
positionerdata-state'open' | 'closed'
contentdata-contained'' (present only while the condition holds)
contentdata-instant'' (present only while the condition holds)
contentdata-resizing'' (present only while the condition holds)
contentdata-sideprops.side
contentdata-sizeprops.size
contentdata-state'open' | 'closed'
confirm-triggerdata-loading'' (present only while the condition holds)
confirm-triggerdata-pressed'' (present only while the condition holds)
confirm-triggerdata-xh-action-control''
confirm-triggerdata-xh-action-display'always'
confirm-triggerdata-xh-action-profile'text'
confirm-triggerdata-xh-action-size'md'
confirm-triggerdata-xh-action-variant'solid'
confirm-triggerdata-xh-ink-surface''
confirm-triggerdata-xh-loading-ring'overlay'
cancel-triggerdata-pressed'' (present only while the condition holds)
cancel-triggerdata-xh-action-control''
cancel-triggerdata-xh-action-display'always'
cancel-triggerdata-xh-action-profile'text'
cancel-triggerdata-xh-action-size'md'
cancel-triggerdata-xh-action-variant'outline'
close-triggerdata-pressed'' (present only while the condition holds)
close-triggerdata-xh-action-control''
close-triggerdata-xh-action-display'always'
close-triggerdata-xh-action-profile'icon'
close-triggerdata-xh-action-size'sm'
close-triggerdata-xh-action-variant'ghost'
resize-triggerdata-resizing'' (present only while the condition holds)
resize-triggerdata-sideprops.side

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-drawer-backdrop-bgbackdropbackgrounddefault--xh-bg-overlay
--xh-drawer-backdrop-blurbackdrop-webkit-backdrop-filter
backdrop-filter
variant=blur--xh-overlay-backdrop-blur
--xh-drawer-backdrop-layerbackdropz-indexdefault--xh-_layer
--xh-drawer-bgcontentbackgrounddefault--xh-material-elevated-bg
--xh-drawer-body-pxbodypadding-inlinedefault--xh-surface-px-sm
--xh-drawer-body-pybodypadding-blockdefault--xh-surface-py-sm
--xh-drawer-bordercontentborderdefault--xh-material-elevated-border
--xh-drawer-close-bg-activeclose-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-drawer-close-bg-focusclose-triggerbackground-colorfocus-visible--xh-_action-variant-bg-focus-visible
--xh-drawer-close-bg-hoverclose-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-drawer-close-fgclose-triggercolordefault--xh-fg-muted
--xh-drawer-close-fg-focusclose-triggercolorfocus-visible--xh-drawer-close-fg-hover
--xh-drawer-close-fg-hoverclose-triggercolordisabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-focus-visible
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-drawer-close-radiusclose-triggerborder-radiusdefault--xh-shape-control
--xh-drawer-close-sizeclose-trigger
content
title
block-size
inline-size
inset-block-start
padding-inline-end
default
has([data-scope='drawer'][data-part='close-trigger'])
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-control-h-sm
--xh-drawer-description-fgdescriptioncolordefault--xh-fg-muted
--xh-drawer-description-font-sizedescriptionfont-sizedefault--xh-text-secondary-size
--xh-drawer-fgcontentcolordefault--xh-material-elevated-fg
--xh-drawer-footer-gapfootergapdefault--xh-control-gap-md
--xh-drawer-footer-ptfooterpadding-block-startdefault--xh-space-2
--xh-drawer-footer-pxcontent
footer
padding-inlinehas([data-scope='drawer'][data-part='body'])--xh-surface-px-sm
--xh-drawer-footer-pycontent
footer
padding-blockhas([data-scope='drawer'][data-part='body'])--xh-overlay-sheet-footer-py
--xh-drawer-gapcontentgapdefault--xh-stack-gap-md
--xh-drawer-header-gapheadergapdefault--xh-stack-gap-sm
--xh-drawer-header-pbcontent
header
padding-block-enddefault
has([data-scope='drawer'][data-part='body'])
--xh-_drawer-header-pb
--xh-space-2
--xh-drawer-header-ptcontent
header
padding-block-starthas([data-scope='drawer'][data-part='body'])--xh-_drawer-header-pt
--xh-drawer-header-pxcontent
header
padding-inlinehas([data-scope='drawer'][data-part='body'])--xh-surface-px-sm
--xh-drawer-icon-sizeclose-trigger
content
root
trigger
--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-glyph-size-md
--xh-glyph-size-xs
--xh-drawer-layercontent
positioner
z-indexdefault--xh-_layer
--xh-drawer-pxcontentpadding-inlinecontained
default
--xh-surface-px-sm
--xh-drawer-pycontentpadding-block-end
padding-block-start
contained
default
--xh-_drawer-header-pt
--xh-overlay-sheet-footer-py
--xh-drawer-radiuscontentborder-end-end-radius
border-end-start-radius
border-start-end-radius
border-start-start-radius
side=bottom
side=left
side=right
side=top
--xh-shape-sheet
--xh-drawer-resize-indicator-lengthresize-triggerblock-size
inline-size
is([data-side='left'], [data-side='right'])
is([data-side='top'], [data-side='bottom'])
side=bottom
side=left
side=right
side=top
--xh-space-8
--xh-drawer-resize-indicator-thicknessresize-triggerblock-size
inline-size
is([data-side='left'], [data-side='right'])
is([data-side='top'], [data-side='bottom'])
side=bottom
side=left
side=right
side=top
--xh-stroke-strong
--xh-drawer-resize-trigger-bgresize-triggerbackgrounddefault--xh-border-control
--xh-drawer-resize-trigger-bg-activeresize-triggerbackgroundresizing--xh-bg-brand
--xh-drawer-resize-trigger-bg-hoverresize-triggerbackgroundhover--xh-border-control-hover
--xh-drawer-resize-trigger-radiusresize-triggerborder-radiusdefault--xh-shape-pill
--xh-drawer-resize-trigger-sizeresize-triggerblock-size
inline-size
side=bottom
side=left
side=right
side=top
--xh-space-2
--xh-drawer-separatorcontent
footer
header
border-block-end
border-block-start
has([data-scope='drawer'][data-part='body'])--xh-material-elevated-separator
--xh-drawer-shadowcontentbox-shadowdefault--xh-material-elevated-shadow
--xh-drawer-sizecontentblock-size
inline-size
side=bottom
side=left
side=right
side=top
--xh-_drawer-size
--xh-drawer-title-fgtitlecolordefault--xh-fg-default
--xh-drawer-title-font-sizetitlefont-sizedefault--xh-text-heading-3-size
--xh-drawer-title-font-weighttitlefont-weightdefault--xh-text-heading-3-weight
--xh-drawer-trigger-bgtrigger--xh-ink-surface
background-color
default
focus-visible
xh-ink-surface
--xh-_action-variant-bg-focus-visible
--xh-_action-variant-bg-rest
--xh-drawer-trigger-bg-activetriggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-drawer-trigger-bg-hovertriggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-drawer-trigger-bg-opentrigger--xh-ink-surface
background-color
focus-visible
state=open
xh-ink-surface
--xh-bg-subtle
--xh-drawer-trigger-bordertriggerborder
border-color
default
focus-visible
--xh-_action-variant-border-focus-visible
--xh-_action-variant-border-rest
--xh-drawer-trigger-border-hovertriggerborder-colordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-border-hover
--xh-_action-variant-border-pressed
--xh-drawer-trigger-border-opentriggerborder
border-color
focus-visible
state=open
--xh-border-control-hover
--xh-drawer-trigger-fgtriggercolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-focus-visible
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-drawer-trigger-font-sizetriggerfont-sizedefault--xh-_action-profile-font-size
--xh-drawer-trigger-font-weighttriggerfont-weightdefault--xh-text-label-weight
--xh-drawer-trigger-gaptriggergapdefault--xh-_action-profile-gap
--xh-drawer-trigger-htriggerblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-drawer-trigger-pxtriggerpadding-inlinedefault--xh-_action-profile-padding-inline
--xh-drawer-trigger-radiustriggerborder-radiusdefault--xh-shape-control

Released under The MIT License