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

查看生态总览
Skip to content

Dialog ​

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="dialog": trigger · backdrop · positioner · content · header · drag-trigger · indicator · title · description · body · footer · confirm-trigger · cancel-trigger · close-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-dialog>
Vue componentsXhDialogBody XhDialogCancelTrigger XhDialogCloseTrigger XhDialogConfirmTrigger XhDialogContent XhDialogDescription XhDialogDragTrigger XhDialogFooter XhDialogHeader XhDialogIndicator XhDialogRoot XhDialogTitle XhDialogTrigger
ComposableuseDialog
State machinedialogMachine
Skin@xihan-ui/styles/dialog.css

Props ​

PropTypeRequired
openboolean
defaultOpenboolean
modalboolean
role'dialog' | 'alertdialog'
closeOnEscapeboolean
closeOnInteractOutsideboolean
restoreFocusboolean
initialFocusstring
sizeSize
variantOverlayBackdropVariant
draggableboolean
unmountOnExitboolean
partsTitleDescriptionParts
translationsPartial<DialogTranslations>
onOpenChange(details: DialogOpenChangeDetails) => void
onExitComplete() => 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
open-changeDialogOpenChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhDialogRootdefaultDialogRootSlotProps
XhDialogRoottrigger—
XhDialogRoottitle—
XhDialogRootdescription—
XhDialogRootbody—
XhDialogRootfooter—

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
XhDialogContentcontainer() => Element | null
XhDialogRoottriggerReactNode
XhDialogRoottitleReactNode
XhDialogRootdescriptionReactNode
XhDialogRootbodyReactNode
XhDialogRootfooterReactNode
XhDialogRootactionsDialogStructureActions
XhDialogRootconfirmTextstring
XhDialogRootcancelTextstring
XhDialogRootonConfirmDialogActionIntents['onConfirm']
XhDialogRootonConfirmErrorDialogActionIntents['onConfirmError']
XhDialogRootonCancelPressDialogActionIntents['onCancelPress']
XhDialogRootchildrenSlotChildren<DialogRootSlotProps>

State ​

Public state is written to data-state.

PartValues
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: OPEN · TOGGLE · CLOSE · CONTROLLED.OPEN · CONTROLLED.CLOSE · PRESS.START · PRESS.END · DRAG.START · DRAG.NUDGE · DRAG.RESET · GESTURE.MOVE · GESTURE.END

Guards: isOpenControlled · canDrag

connect API ​

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

MemberType
openboolean
offsetDialogOffset
draggingboolean
pendingboolean
actionErrorDialogConfirmErrorDetails | null
setOpen(next: boolean) => void
confirm() => void
cancel() => void
getTriggerProps() => T['button']
getBackdropProps() => T['element']
getPositionerProps() => T['element']
getContentProps() => T['element']
getHeaderProps() => T['element']
getDragTriggerProps() => T['button']
getIndicatorProps() => T['element']
getTitleProps() => T['element']
getDescriptionProps() => T['element']
getBodyProps() => T['element']
getFooterProps() => T['element']
getConfirmTriggerProps() => T['button']
getCancelTriggerProps() => T['button']
getCloseTriggerProps() => T['button']
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 / Spacedialog.kbd.open-on-trigger
Escapedialog.kbd.escape
Tabdialog.kbd.tab
Shift+Tabdialog.kbd.shift-tab
Enter / Spacedialog.kbd.press
ArrowUp / ArrowDown / ArrowLeft / ArrowRightdialog.kbd.drag-move
Shift+ArrowUp / Shift+ArrowDown / Shift+ArrowLeft / Shift+ArrowRightdialog.kbd.drag-large
Enter / Spacedialog.kbd.drag-reset

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
drag-triggeraria-disabled'false' | 'true'
drag-triggeraria-labeltranslations.dragTrigger
indicatoraria-hidden'true'
confirm-triggeraria-busy'true' | undefined
confirm-triggeraria-disabled'true' | undefined
close-triggeraria-labeltranslations.close

Style reference ​

Skin ​

@xihan-ui/styles/dialog.css is written against [data-scope="dialog"][data-part="trigger"] part selectors; the published build uses the mount class .xh-scope-dialog 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
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-instant'' (present only while the condition holds)
backdropdata-state'open' | 'closed'
backdropdata-variantprops.variant
positionerdata-positioned''
positionerdata-state'open' | 'closed'
contentdata-draggable'' (present only while the condition holds)
contentdata-dragging'' (present only while the condition holds)
contentdata-instant'' (present only while the condition holds)
contentdata-sizeprops.size
contentdata-state'open' | 'closed'
headerdata-draggable'' (present only while the condition holds)
drag-triggerdata-disabled'' (present only while the condition holds)
drag-triggerdata-dragging'' (present only while the condition holds)
titledata-draggable'' (present only while the condition holds)
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'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-dialog-backdrop-bgbackdropbackgrounddefault--xh-bg-overlay
--xh-dialog-backdrop-blurbackdrop-webkit-backdrop-filter
backdrop-filter
variant=blur--xh-overlay-backdrop-blur
--xh-dialog-backdrop-filterbackdrop
content
-webkit-backdrop-filter
backdrop-filter
default
variant=blur
--xh-dialog-backdrop-blur
--xh-material-elevated-backdrop
--xh-dialog-backdrop-layerbackdropz-indexdefault--xh-_layer
--xh-dialog-bgcontentbackgrounddefault--xh-material-elevated-bg
--xh-dialog-body-pxbodypadding-inlinedefault--xh-overlay-sheet-px
--xh-dialog-body-pybodypadding-blockdefault--xh-overlay-sheet-body-py
--xh-dialog-bordercontentborderdefault--xh-material-elevated-border
--xh-dialog-close-bg-activeclose-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-dialog-close-bg-focusclose-triggerbackground-colorfocus-visible--xh-_action-variant-bg-focus-visible
--xh-dialog-close-bg-hoverclose-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-dialog-close-fgclose-triggercolordefault--xh-fg-muted
--xh-dialog-close-fg-focusclose-triggercolorfocus-visible--xh-dialog-close-fg-hover
--xh-dialog-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-dialog-close-radiusclose-triggerborder-radiusdefault--xh-shape-control
--xh-dialog-close-sizeclose-trigger
content
title
block-size
inline-size
inset-block-start
padding-inline-end
default
has([data-scope='dialog'][data-part='close-trigger'])
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-control-h-sm
--xh-dialog-content-backdrop-filtercontent-webkit-backdrop-filter
backdrop-filter
default--xh-dialog-backdrop-filter
--xh-dialog-description-fgdescriptioncolordefault--xh-fg-muted
--xh-dialog-description-font-sizedescriptionfont-sizedefault--xh-text-secondary-size
--xh-dialog-drag-trigger-min-hdrag-triggermin-block-sizedefault--xh-space-6
--xh-dialog-drag-trigger-radiusdrag-triggerborder-radiusdefault--xh-shape-control
--xh-dialog-fgcontentcolordefault--xh-material-elevated-fg
--xh-dialog-footer-gapfootergapdefault--xh-control-gap-md
--xh-dialog-footer-ptfooterpadding-block-startdefault--xh-space-2
--xh-dialog-footer-pxcontent
footer
padding-inlinehas([data-scope='dialog'][data-part='body'])--xh-overlay-sheet-px
--xh-dialog-footer-pycontent
footer
padding-blockhas([data-scope='dialog'][data-part='body'])--xh-overlay-sheet-footer-py
--xh-dialog-gapcontentgapdefault--xh-stack-gap-md
--xh-dialog-header-gapheadergapdefault--xh-stack-gap-sm
--xh-dialog-header-pbcontent
header
padding-block-enddefault
has([data-scope='dialog'][data-part='body'])
--xh-_dialog-header-pb
--xh-space-2
--xh-dialog-header-ptcontent
header
padding-block-starthas([data-scope='dialog'][data-part='body'])--xh-_dialog-header-pt
--xh-dialog-header-pxcontent
header
padding-inlinehas([data-scope='dialog'][data-part='body'])--xh-overlay-sheet-px
--xh-dialog-icon-sizeclose-trigger
content
trigger
--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-glyph-size-md
--xh-glyph-size-xs
--xh-dialog-indicator-bgindicatorbackgrounddefault--xh-_tone-subtle
--xh-dialog-indicator-fgindicatorcolordefault--xh-_tone-fg
--xh-dialog-indicator-mark-sizeindicator--xh-icon-sizedefault--xh-dialog-indicator-size
--xh-dialog-indicator-radiusindicatorborder-radiusdefault--xh-shape-circle
--xh-dialog-indicator-sizeindicator--xh-icon-size
block-size
inline-size
default--xh-glyph-size-md
--xh-dialog-layerpositionerz-indexdefault--xh-_layer
--xh-dialog-max-wcontentmax-inline-sizedefault--xh-_dialog-max-w
--xh-dialog-positioner-paddingpositionerpadding-block-end
padding-block-start
padding-inline
default--xh-space-4
--xh-dialog-pxcontentpadding-inlinedefault--xh-overlay-sheet-px
--xh-dialog-pycontentpadding-block-end
padding-block-start
default--xh-_dialog-header-pt
--xh-overlay-sheet-body-py
--xh-dialog-radiuscontentborder-radiusdefault--xh-shape-sheet
--xh-dialog-separatorcontent
footer
header
border-block-end
border-block-start
has([data-scope='dialog'][data-part='body'])
has([data-scope='dialog'][data-part='footer'])
--xh-material-elevated-separator
--xh-dialog-shadowcontentbox-shadowdefault--xh-material-elevated-shadow
--xh-dialog-title-fgtitlecolordefault--xh-fg-default
--xh-dialog-title-font-sizetitlefont-sizedefault--xh-text-heading-3-size
--xh-dialog-title-font-weighttitlefont-weightdefault--xh-text-heading-3-weight

Released under The MIT License