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

查看生态总览
Skip to content

Checkbox ​

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": root · indicator · hidden-input · label · text

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>
Vue componentsXhCheckbox
ComposableuseCheckbox
State machinecheckboxMachine
Skin@xihan-ui/styles/checkbox.css

Props ​

PropTypeRequired
checkedCheckboxCheckedState
defaultCheckedCheckboxCheckedState
ariaLabelstring
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
namestring
valuestring
toneTone
sizeSize
onCheckedChange(details: CheckboxCheckedChangeDetails) => void

Events ​

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

EventPayload
checked-changeCheckboxCheckedChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhCheckboxdefault—
XhCheckboxindicator—

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
XhCheckboxindicatorReactNode
XhCheckboxchildrenReactNode

State ​

Public state is written to data-state.

PartValues
root'indeterminate' | 'checked' | 'unchecked'
indicator'indeterminate' | 'checked' | 'unchecked'
label'indeterminate' | 'checked' | 'unchecked'
text'indeterminate' | 'checked' | 'unchecked'

The following names are internal to the state machine.

States: off · on · indeterminate

Events: TOGGLE · CHECK · UNCHECK · CONTROLLED.ON · CONTROLLED.OFF · CONTROLLED.INDETERMINATE · FORM.RESET · PRESS.START · PRESS.END

Guards: isCheckedControlled · defaultsToChecked · defaultsToIndeterminate · canPress

connect API ​

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

MemberType
checkedCheckboxCheckedState
setChecked(next: boolean) => void
getRootProps() => T['button']
getIndicatorProps() => T['element']
getHiddenInputProps() => T['input']
getLabelProps() => T['label']
getTextProps() => 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
Space / Entercheckbox.kbd.toggle
Space / Entercheckbox.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-checked'mixed' | 'true' | 'false'
rootaria-invalid'true' | 'false'
rootaria-labelprops.ariaLabel
rootaria-readonly'true' | 'false'
rootaria-required'true' | 'false'
rootrole'checkbox'
indicatoraria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/checkbox.css is written against [data-scope="checkbox"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-checkbox 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-pressed'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'indeterminate' | 'checked' | 'unchecked'
rootdata-toneprops.tone
rootdata-xh-action-control''
rootdata-xh-action-display'always'
rootdata-xh-action-profile'icon'
rootdata-xh-action-sizeprops.size
rootdata-xh-action-variant'outline'
indicatordata-state'indeterminate' | 'checked' | 'unchecked'
indicatordata-xh-check-mark'indeterminate' | 'checked' | 'unchecked'
indicatordata-xh-check-mark-profile'box'
labeldata-disabled'' (present only while the condition holds)
labeldata-invalid'' (present only while the condition holds)
labeldata-readonly'' (present only while the condition holds)
labeldata-sizeprops.size
labeldata-state'indeterminate' | 'checked' | 'unchecked'
textdata-disabled'' (present only while the condition holds)
textdata-invalid'' (present only while the condition holds)
textdata-state'indeterminate' | 'checked' | 'unchecked'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-checkbox-bgroot--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
transparent
--xh-checkbox-bg-checkedroot--xh-ink-surface
background-color
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
readonly
state=checked
state=indeterminate
xh-ink-surface
--xh-_checkbox-accent
--xh-checkbox-bg-checked-pressedrootbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
state=checked
state=indeterminate
--xh-_tone-active
--xh-checkbox-bg-disabledroot--xh-ink-surface
background-color
disabled
xh-ink-surface
--xh-bg-subtle
--xh-checkbox-bg-pressedrootbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-checkbox-borderlabel
root
border
border-color
@media (hover: hover)
contrast=more
default
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
not([data-readonly])
pressed
readonly
state=unchecked
where([data-contrast='more'])
--xh-border-strong
--xh-checkbox-border-checkedlabel
root
border
border-color
@media (hover: hover)
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
not([data-readonly])
pressed
readonly
state=checked
state=indeterminate
--xh-_checkbox-accent
--xh-checkbox-border-disabledrootborder-colordisabled--xh-border-default
--xh-checkbox-border-hoverlabel
root
border-color@media (hover: hover)
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
not([data-readonly])
pressed
readonly
--xh-border-control-hover
--xh-checkbox-border-invalidlabel
root
border
border-color
@media (hover: hover)
disabled
focus-visible
hover
invalid
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
not([data-readonly])
pressed
readonly
state=checked
state=indeterminate
--xh-border-invalid
--xh-checkbox-fgrootcolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_checkbox-on-accent
--xh-checkbox-fg-disabledindicator
root
--xh-check-mark-fg
color
disabled
state=indeterminate
--xh-fg-disabled
--xh-checkbox-fg-invalidlabel
text
colorinvalid--xh-fg-danger
--xh-checkbox-icon-sizeroot--xh-icon-sizedefault--xh-_checkbox-glyph
--xh-checkbox-indicator-fgindicator--xh-check-mark-fgstate=indeterminate--xh-_checkbox-on-accent
--xh-checkbox-label-fglabelcolordefault--xh-fg-default
--xh-checkbox-label-fg-disabledlabelcolordisabled--xh-fg-subtle
--xh-checkbox-label-font-sizelabelfont-sizedefault--xh-_checkbox-label-font-size
--xh-checkbox-label-gaplabelgapdefault--xh-_checkbox-label-gap
--xh-checkbox-label-leadinglabelline-heightdefault--xh-leading-normal
--xh-checkbox-radiusrootborder-radiusdefault--xh-shape-inset
--xh-checkbox-shadowrootbox-shadowdefault
disabled
focus-visible
hover
is(:active, [data-pressed])
is(:hover, [data-loading])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-ring-width
none

Released under The MIT License