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

查看生态总览
Skip to content

ToggleGroup ​

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="toggle-group": root · item · hidden-input

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-toggle-group>
Vue componentsXhToggleGroupHiddenInput XhToggleGroupItem XhToggleGroupRoot
ComposableuseToggleGroup
State machinetoggleGroupMachine
Skin@xihan-ui/styles/toggle-group.css

Props ​

PropTypeRequired
collectionToggleGroupNode<V>[]
valueKeySelectionValueKey<V>
valueToggleGroupValue<V>
defaultValueToggleGroupValue<V>
multipleboolean
ariaLabelstring
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
disallowEmptyboolean
variantActionVariant
toneTone
sizeSize
fullWidthboolean
separatorsboolean
namestring
orientationOrientation
dirDirection
loopboolean
rovingFocusboolean
onValueChange(details: ToggleGroupValueChangeDetails<V>) => void

ToggleGroupNode ​

Elements of collection.

FieldTypeRequired
valueVYes
labelstring
disabledboolean

Events ​

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

EventPayload
value-changeToggleGroupValueChangeDetails

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
XhToggleGroupItemvalueunknownYes
XhToggleGroupItemdisabledboolean
XhToggleGroupRootrenderItem(node: ToggleGroupNodeMeta<V>) => ReactNode
XhToggleGroupRootchildrenReactNode

State ​

Public state is written to data-state.

PartValues
item'on' | 'off'

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · ITEM.TOGGLE · ITEM.FOCUS · GROUP.BLUR · FORM.RESET · PRESS.START · PRESS.END

Guards: canPress · canToggle

connect API ​

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

MemberType
valueV[]
collectionreadonly ToggleGroupNodeMeta<V>[]
focusedValueV | null
multipleboolean
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
orientationOrientation
separatorsboolean
isSelected(value: V) => boolean
setValue(next: ToggleGroupValue<V>) => void
getRootProps() => T['element']
getItemProps(props: ToggleGroupItemProps<V>) => T['button']
getHiddenInputProps() => T['input']

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
Tab / Shift+Tabtoggle-group.kbd.tab
ArrowRight / ArrowDowntoggle-group.kbd.next
ArrowLeft / ArrowUptoggle-group.kbd.prev
Hometoggle-group.kbd.first
Endtoggle-group.kbd.last
Enter / Spacetoggle-group.kbd.toggle
Enter / Spacetoggle-group.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-invalidundefined | 'true' | 'false'
rootaria-labelprops.ariaLabel
rootaria-orientationundefined | props.orientation
rootaria-readonlyundefined | 'true' | 'false'
rootaria-requiredundefined | 'true' | 'false'
rootrole'group' | 'radiogroup'
itemaria-checkedundefined | 'true' | 'false'
itemaria-disabled'true' | 'false'
itemaria-pressed'true' | 'false' | undefined
itemroleundefined | 'radio'
hidden-inputaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/toggle-group.css is written against [data-scope="toggle-group"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-toggle-group 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-disabled'' (present only while the condition holds)
rootdata-full-width'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-orientationprops.orientation
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
rootdata-variantprops.variant
itemdata-disabled'' (present only while the condition holds)
itemdata-invalid'' (present only while the condition holds)
itemdata-pressed'' (present only while the condition holds)
itemdata-readonly'' (present only while the condition holds)
itemdata-state'on' | 'off'
itemdata-xh-action-control''
itemdata-xh-action-display'always'
itemdata-xh-action-profile'text'
itemdata-xh-action-sizeprops.size
itemdata-xh-action-variantprops.variant

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-toggle-group-border-invalidrootborderinvalid--xh-border-invalid
--xh-toggle-group-item-bgitem--xh-ink-surface
background-color
default
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
readonly
xh-ink-surface
--xh-_toggle-group-item-bg
--xh-toggle-group-item-bg-activeitembackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_toggle-group-item-bg-active
--xh-toggle-group-item-bg-disableditem--xh-ink-surface
background-color
disabled
xh-ink-surface
--xh-bg-muted
--xh-toggle-group-item-bg-hoveritembackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_toggle-group-item-bg-hover
--xh-toggle-group-item-bg-onitem--xh-ink-surface
background-color
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
readonly
state=on
xh-ink-surface
--xh-_toggle-group-item-bg-on
--xh-toggle-group-item-bg-on-activeitembackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=on
--xh-_toggle-group-item-bg-on-active
--xh-toggle-group-item-bg-on-disableditem--xh-ink-surface
background-color
disabled
state=on
xh-ink-surface
--xh-_toggle-group-item-bg-on
--xh-toggle-group-item-bg-on-hoveritembackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
state=on
--xh-_toggle-group-item-bg-on-hover
--xh-toggle-group-item-borderitemborder
border-color
default
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_toggle-group-item-border
--xh-toggle-group-item-border-disableditemborder-colordisabled--xh-border-subtle
--xh-toggle-group-item-border-onitemborder
border-color
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=on
--xh-_toggle-group-item-border-on
--xh-toggle-group-item-border-on-disableditemborder-colordisabled
state=on
--xh-_toggle-group-item-border-on
--xh-toggle-group-item-fgitemcolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_toggle-group-item-fg
--xh-toggle-group-item-fg-disableditemcolordisabled--xh-fg-disabled
--xh-toggle-group-item-fg-onitemcolordisabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=on
--xh-_toggle-group-item-fg-on
--xh-toggle-group-item-fg-on-disableditemcolordisabled
state=on
--xh-_toggle-group-item-fg-on
--xh-toggle-group-item-font-sizeitemfont-sizedefault--xh-_toggle-group-font-size
--xh-toggle-group-item-font-weightitemfont-weightdefault--xh-text-label-weight
--xh-toggle-group-item-gapitemgapdefault--xh-_toggle-group-gap
--xh-toggle-group-item-hitemblock-sizedefault--xh-_toggle-group-h
--xh-toggle-group-item-pxitempadding-inlinedefault--xh-_toggle-group-px
--xh-toggle-group-item-radiusitem
root
border-end-end-radius
border-end-start-radius
border-radius
border-start-end-radius
border-start-start-radius
first-child
first-of-type
invalid
last-child
last-of-type
orientation=horizontal
orientation=vertical
variant=outline
--xh-shape-control
--xh-toggle-group-item-shadowitem
root
box-shadowdisabled
focus-visible
hover
is(:active, [data-pressed])
is(:hover, [data-loading])
is(:not([data-variant])
loading
not([data-disabled])
not([data-loading])
pressed
state=on
variant
variant=solid
--xh-_toggle-group-item-highlight-on
--xh-ring-width
--xh-toggle-group-outline-colorrootbordervariant=outline--xh-_tone-border-control
--xh-toggle-group-separator-colorrootbackgroundxh-toggle-group-separator--xh-fg-default
--xh-toggle-group-separator-color-disabledrootbackgrounddisabled
xh-toggle-group-separator
--xh-border-subtle
--xh-toggle-group-separator-opacityrootopacityxh-toggle-group-separator--xh-control-separator-opacity
--xh-toggle-group-separator-opacity-disabledrootopacitydisabled
xh-toggle-group-separator
--xh-control-separator-disabled-opacity
--xh-toggle-group-separator-radiusrootborder-radiusxh-toggle-group-separator--xh-shape-pill
--xh-toggle-group-separator-sizerootblock-size
inline-size
orientation=horizontal
orientation=vertical
xh-toggle-group-separator
--xh-_group-separator-size
--xh-toggle-group-separator-thicknessrootblock-size
inline-size
margin-block-start
margin-inline-start
orientation=horizontal
orientation=vertical
xh-toggle-group-separator
--xh-stroke-thin

Released under The MIT License