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

查看生态总览
Skip to content

CheckboxGroup ​

Data entry 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="checkbox-group": root · label · item · indicator · item-text · item-description · hidden-input · select-all-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-checkbox-group>
Vue componentsXhCheckboxGroupIndicator XhCheckboxGroupItem XhCheckboxGroupItemDescription XhCheckboxGroupItemText XhCheckboxGroupLabel XhCheckboxGroupRoot XhCheckboxGroupSelectAllTrigger
ComposableuseCheckboxGroup
State machinecheckboxGroupMachine
Skin@xihan-ui/styles/checkbox-group.css

Props ​

PropTypeRequired
collectionCheckboxGroupNode<V>[]
valueKeySelectionValueKey<V>
valueV[]
defaultValueV[]
itemValuesV[]
minnumber
maxnumber
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
namestring
orientationOrientation
toneTone
sizeSize
variantCheckboxGroupVariant
labelledboolean
ariaLabelstring
onValueChange(details: CheckboxGroupValueChangeDetails<V>) => void

CheckboxGroupNode ​

Elements of collection.

FieldTypeRequired
valueVYes
labelstring
descriptionstring
disabledboolean

Events ​

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

EventPayload
value-changeCheckboxGroupValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhCheckboxGroupRootdefaultCheckboxGroupRootSlotProps<V>
XhCheckboxGroupRootlabel—
XhCheckboxGroupRootitemCheckboxGroupNodeMeta<V>

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
XhCheckboxGroupItemvalueunknownYes
XhCheckboxGroupItemdisabledboolean
XhCheckboxGroupRootlabelReactNode
XhCheckboxGroupRootrenderItem(node: CheckboxGroupNodeMeta<V>) => ReactNode
XhCheckboxGroupRootchildrenSlotChildren<CheckboxGroupRootSlotProps<V>>

State ​

Public state is written to data-state.

PartValues
item'checked' | 'unchecked'
indicator'checked' | 'unchecked'
item-text'checked' | 'unchecked'
item-description'checked' | 'unchecked'
hidden-input'checked' | 'unchecked'
select-all-triggerresolveCheckedState(value, prop('itemValues') ?? [])

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · ITEM.TOGGLE · ALL.TOGGLE · FORM.RESET · PRESS.START · PRESS.END

Guards: editable · canPress

connect API ​

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

MemberType
valueV[]
collectionreadonly CheckboxGroupNodeMeta<V>[]
checkedStateCheckboxGroupCheckedState
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
atMaxboolean
atMinboolean
isChecked(value: V) => boolean
setValue(next: V[]) => void
toggleValue(value: V) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getItemProps(props: CheckboxGroupItemProps<V>) => T['element']
getIndicatorProps(props: CheckboxGroupItemProps<V>) => T['element']
getItemTextProps(props: CheckboxGroupItemProps<V>) => T['element']
getItemDescriptionProps(props: CheckboxGroupItemProps<V>) => T['element']
getHiddenInputProps(props: CheckboxGroupItemProps<V>) => T['input']
getSelectAllTriggerProps() => T['element']

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+Tabcheckbox-group.kbd.tab
Spacecheckbox-group.kbd.toggle
Spacecheckbox-group.kbd.toggle-all
Spacecheckbox-group.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-labelprops.ariaLabel
rootaria-labelledbyid of the label part | undefined
rootrole'group'
itemaria-checked'true' | 'false'
itemaria-disabled'true' | 'false'
itemaria-invalid'true' | 'false'
itemaria-readonly'true' | 'false'
itemrole'checkbox'
indicatoraria-hidden'true'
hidden-inputaria-hidden'true'
select-all-triggeraria-checked'true' | 'mixed' | 'false'
select-all-triggeraria-disabled'false' | 'true'
select-all-triggeraria-labelledbyid of the label part id of the select-all-trigger part | id of the select-all-trigger part
select-all-triggeraria-readonly'true' | 'false'
select-all-triggerrole'checkbox'

Style reference ​

Skin ​

@xihan-ui/styles/checkbox-group.css is written against [data-scope="checkbox-group"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-checkbox-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-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
labeldata-required'' (present only while the condition holds)
itemdata-disabled'' (present only while the condition holds)
itemdata-pressed'' (present only while the condition holds)
itemdata-readonly'' (present only while the condition holds)
itemdata-state'checked' | 'unchecked'
itemdata-xh-action-control''
itemdata-xh-action-display'always'
itemdata-xh-action-profile'row'
itemdata-xh-action-size'xs'
itemdata-xh-action-variant'outline' | 'ghost'
itemdata-xh-choice-card'' (present only while the condition holds)
indicatordata-disabled'' (present only while the condition holds)
indicatordata-state'checked' | 'unchecked'
indicatordata-xh-check-mark'checked' | 'unchecked'
indicatordata-xh-check-mark-profile'box'
item-textdata-disabled'' (present only while the condition holds)
item-textdata-state'checked' | 'unchecked'
item-descriptiondata-disabled'' (present only while the condition holds)
item-descriptiondata-state'checked' | 'unchecked'
hidden-inputdata-disabled'' (present only while the condition holds)
hidden-inputdata-state'checked' | 'unchecked'
select-all-triggerdata-disabled'' (present only while the condition holds)
select-all-triggerdata-pressed'' (present only while the condition holds)
select-all-triggerdata-readonly'' (present only while the condition holds)
select-all-triggerdata-stateresolveCheckedState(value, prop('itemValues') ?? [])
select-all-triggerdata-xh-action-control''
select-all-triggerdata-xh-action-display'always'
select-all-triggerdata-xh-action-profile'row'
select-all-triggerdata-xh-action-size'xs'
select-all-triggerdata-xh-action-variant'ghost'
select-all-triggerdata-xh-check-markresolveCheckedState(value, prop('itemValues') ?? [])
select-all-triggerdata-xh-check-mark-profile'row'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-checkbox-group-card-title-font-weightitem
item-text
font-weightxh-choice-card--xh-text-label-weight
--xh-checkbox-group-gaprootgapdefault--xh-space-2
--xh-checkbox-group-icon-sizeroot--xh-icon-sizedefault--xh-_checkbox-group-glyph
--xh-checkbox-group-indicator-bgindicator
root
select-all-trigger
background-colordefaulttransparent
--xh-checkbox-group-indicator-bg-checkedindicator
select-all-trigger
background-coloris([data-state='checked'], [data-state='indeterminate'])
state=checked
state=indeterminate
--xh-_checkbox-group-accent
--xh-checkbox-group-indicator-bg-checked-pressedindicator
item
root
select-all-trigger
background-colordisabled
is(:active, [data-pressed])
is([data-state='checked'], [data-state='indeterminate'])
not([data-disabled])
not([data-readonly])
pressed
readonly
state=checked
state=indeterminate
--xh-_tone-active
--xh-checkbox-group-indicator-bg-disabledindicator
item
root
select-all-trigger
background-colordisabled--xh-bg-subtle
--xh-checkbox-group-indicator-bg-pressedindicator
item
root
select-all-trigger
background-colordisabled
is(:active, [data-pressed])
not([data-disabled])
not([data-readonly])
pressed
readonly
--xh-_checkbox-group-host-bg-pressed
--xh-checkbox-group-indicator-borderindicator
select-all-trigger
borderdefault--xh-border-strong
--xh-checkbox-group-indicator-border-checkedindicator
select-all-trigger
border-coloris([data-state='checked'], [data-state='indeterminate'])
state=checked
state=indeterminate
--xh-_checkbox-group-accent
--xh-checkbox-group-indicator-border-disabledindicator
item
root
select-all-trigger
border-colordisabled--xh-border-default
--xh-checkbox-group-indicator-border-hoverindicator
item
root
select-all-trigger
border-color@media (hover: hover)
disabled
hover
invalid
not([data-disabled])
not([data-invalid])
not([data-readonly])
not([data-state='checked'])
not([data-state='indeterminate'])
readonly
state=checked
state=indeterminate
--xh-border-control-hover
--xh-checkbox-group-indicator-border-invalidindicator
root
border-colorinvalid--xh-border-invalid
--xh-checkbox-group-indicator-fgindicator
select-all-trigger
--xh-check-mark-fg
color
default--xh-_checkbox-group-on-accent
--xh-checkbox-group-indicator-fg-disabledindicator
item
root
select-all-trigger
--xh-check-mark-fg
color
disabled--xh-fg-disabled
--xh-checkbox-group-indicator-font-sizeindicator
select-all-trigger
font-sizedefault--xh-_checkbox-group-glyph
--xh-checkbox-group-indicator-radiusindicator
select-all-trigger
border-radiusdefault--xh-shape-inset
--xh-checkbox-group-indicator-shadowindicator
select-all-trigger
box-shadowdefaultnone
--xh-checkbox-group-indicator-sizeindicator
select-all-trigger
--xh-check-mark-box-size
block-size
inline-size
default--xh-_checkbox-group-box
--xh-checkbox-group-item-bg-hoveritembackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-bg-subtle
--xh-checkbox-group-item-bg-presseditembackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-checkbox-group-item-description-fgitem-descriptioncolordefault--xh-fg-muted
--xh-checkbox-group-item-description-fg-disableditem
item-description
colordisabled--xh-fg-disabled
--xh-checkbox-group-item-description-font-sizeitem-descriptionfont-sizedefault--xh-text-secondary-size
--xh-checkbox-group-item-fgitemcolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-checkbox-group-item-fg-disableditemcolordisabled--xh-fg-disabled
--xh-checkbox-group-item-font-sizeitemfont-sizedefault--xh-_checkbox-group-font-size
--xh-checkbox-group-item-gapitemgapdefault--xh-_checkbox-group-gap
--xh-checkbox-group-item-radiusitemborder-radiusdefault--xh-shape-control
--xh-checkbox-group-item-row-gapitemrow-gaphas(> [data-scope='checkbox-group'][data-part='item-description'])
not([data-xh-choice-card])
xh-choice-card
--xh-space-1
--xh-checkbox-group-label-fglabelcolordefault--xh-fg-muted
--xh-checkbox-group-label-fg-disabledlabel
root
colordisabled--xh-fg-subtle
--xh-checkbox-group-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-checkbox-group-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-checkbox-group-select-all-trigger-bg-hoverselect-all-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-bg-subtle
--xh-checkbox-group-select-all-trigger-bg-pressedselect-all-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-checkbox-group-select-all-trigger-fgselect-all-triggercolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-checkbox-group-select-all-trigger-fg-disabledselect-all-triggercolordisabled--xh-fg-disabled
--xh-checkbox-group-select-all-trigger-font-sizeselect-all-triggerfont-sizedefault--xh-_checkbox-group-font-size
--xh-checkbox-group-select-all-trigger-font-weightselect-all-triggerfont-weightdefault--xh-font-weight-medium
--xh-checkbox-group-select-all-trigger-gapselect-all-triggergapdefault--xh-_checkbox-group-gap
--xh-checkbox-group-select-all-trigger-radiusselect-all-triggerborder-radiusdefault--xh-shape-inset

Released under The MIT License