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

查看生态总览
Skip to content

RadioGroup ​

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="radio-group": root · label · thumb · item · item-icon · item-text · item-description · indicator · 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-radio-group>
Vue componentsXhRadioGroupItem XhRadioGroupItemDescription XhRadioGroupItemIcon XhRadioGroupItemText XhRadioGroupLabel XhRadioGroupRoot XhRadioGroupThumb
ComposableuseRadioGroup
State machineradioGroupMachine
Skin@xihan-ui/styles/radio-group.css

Props ​

PropTypeRequired
collectionRadioGroupNode<V>[]
valueKeySelectionValueKey<V>
valueV | null
defaultValueV | null
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
orientationOrientation
dirDirection
namestring
loopboolean
blockboolean
toneTone
sizeSize
variantRadioGroupVariant
labelledboolean
ariaLabelstring
onValueChange(details: RadioGroupValueChangeDetails<V>) => void

RadioGroupNode ​

Elements of collection.

FieldTypeRequired
valueVYes
labelstring
descriptionstring
iconstring
disabledboolean

Events ​

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

EventPayload
value-changeRadioGroupValueChangeDetails

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
XhRadioGroupItemvalueunknownYes
XhRadioGroupItemdisabledboolean
XhRadioGroupRootlabelReactNode
XhRadioGroupRootrenderItem(node: RadioGroupNodeMeta<V>) => ReactNode
XhRadioGroupRootchildrenReactNode

State ​

Public state is written to data-state.

PartValues
item'checked' | 'unchecked'
item-icon'checked' | 'unchecked'
item-text'checked' | 'unchecked'
item-description'checked' | 'unchecked'
indicator'checked' | 'unchecked'
hidden-input'checked' | 'unchecked'

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · ITEM.SELECT · ITEM.FOCUS · GROUP.BLUR · FORM.RESET · THUMB.MEASURE · PRESS.START · PRESS.END

Guards: canPress

connect API ​

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

MemberType
valueV | null
collectionreadonly RadioGroupNodeMeta<V>[]
focusedValueV | null
variantRadioGroupVariant
setValue(next: V) => void
measure() => void
getRootProps() => T['element']
getLabelProps() => T['element']
getItemProps(props: RadioGroupItemProps<V>) => T['element']
getItemIconProps(props: RadioGroupItemProps<V>) => T['element']
getItemTextProps(props: RadioGroupItemProps<V>) => T['element']
getItemDescriptionProps(props: RadioGroupItemProps<V>) => T['element']
getIndicatorProps(props: RadioGroupItemProps<V>) => T['element']
getThumbProps() => T['element']
getHiddenInputProps(props: RadioGroupItemProps<V>) => 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+Tabradio-group.kbd.tab
ArrowDown / ArrowRightradio-group.kbd.next
ArrowUp / ArrowLeftradio-group.kbd.prev
Spaceradio-group.kbd.select
Spaceradio-group.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-invalid'true' | 'false'
rootaria-labelprops.ariaLabel
rootaria-labelledbyid of the label part | undefined
rootaria-orientation'horizontal' | 'vertical'
rootaria-readonly'true' | 'false'
rootaria-required'true' | 'false'
rootrole'radiogroup'
thumbaria-hidden'true'
itemaria-checked'true' | 'false'
itemaria-disabled'true' | 'false'
itemrole'radio'
item-iconaria-hidden'true'
indicatoraria-hidden'true'
hidden-inputaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/radio-group.css is written against [data-scope="radio-group"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-radio-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-block'' (present only while the condition holds)
rootdata-disabled'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-orientation'horizontal' | 'vertical'
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
thumbdata-instant'' (present only while the condition holds)
thumbdata-valuecontext.get('value')
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'checked' | 'unchecked'
itemdata-xh-action-controlundefined | ''
itemdata-xh-action-displayundefined | 'always'
itemdata-xh-action-profileundefined | 'row'
itemdata-xh-action-sizeundefined | 'xs'
itemdata-xh-action-variantundefined | 'outline' | 'ghost'
itemdata-xh-choice-card'' (present only while the condition holds)
item-icondata-disabled'' (present only while the condition holds)
item-icondata-invalid'' (present only while the condition holds)
item-icondata-readonly'' (present only while the condition holds)
item-icondata-state'checked' | 'unchecked'
item-textdata-disabled'' (present only while the condition holds)
item-textdata-invalid'' (present only while the condition holds)
item-textdata-readonly'' (present only while the condition holds)
item-textdata-state'checked' | 'unchecked'
item-descriptiondata-disabled'' (present only while the condition holds)
item-descriptiondata-invalid'' (present only while the condition holds)
item-descriptiondata-readonly'' (present only while the condition holds)
item-descriptiondata-state'checked' | 'unchecked'
indicatordata-disabled'' (present only while the condition holds)
indicatordata-invalid'' (present only while the condition holds)
indicatordata-readonly'' (present only while the condition holds)
indicatordata-state'checked' | 'unchecked'
hidden-inputdata-disabled'' (present only while the condition holds)
hidden-inputdata-invalid'' (present only while the condition holds)
hidden-inputdata-readonly'' (present only while the condition holds)
hidden-inputdata-state'checked' | 'unchecked'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-radio-group-card-title-font-weightitem
item-text
font-weightxh-choice-card--xh-text-label-weight
--xh-radio-group-gaprootgapdefault--xh-space-2
--xh-radio-group-icon-sizeroot--xh-icon-sizedefault
size=lg
size=sm
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-radio-group-indicator-bgindicatorbackgrounddefaulttransparent
--xh-radio-group-indicator-bg-disabledindicator
item
backgrounddisabled--xh-bg-subtle
--xh-radio-group-indicator-bg-pressedindicator
item
backgrounddisabled
is(:active, [data-pressed])
not([data-disabled])
not([data-readonly])
pressed
readonly
--xh-_radio-group-host-bg-pressed
--xh-radio-group-indicator-borderindicatorborderdefault--xh-border-strong
--xh-radio-group-indicator-border-checkedindicatorborder-colorstate=checked--xh-_radio-group-accent
--xh-radio-group-indicator-border-disabledindicator
item
border-colordisabled--xh-border-default
--xh-radio-group-indicator-border-hoverindicator
item
border-colordisabled
hover
invalid
not([data-disabled])
not([data-invalid])
not([data-readonly])
not([data-state='checked'])
readonly
state=checked
--xh-border-control-hover
--xh-radio-group-indicator-border-invalidindicatorborder-colorinvalid
state=checked
--xh-border-invalid
--xh-radio-group-indicator-dotindicatorbackgrounddefault--xh-_radio-group-accent
--xh-radio-group-indicator-dot-disabledindicator
item
backgrounddisabled--xh-fg-disabled
--xh-radio-group-indicator-dot-pressedindicator
item
backgrounddisabled
is(:active, [data-pressed])
not([data-disabled])
not([data-readonly])
pressed
readonly
state=checked
--xh-_tone-active
--xh-radio-group-indicator-radiusindicatorborder-radiusdefault--xh-shape-circle
--xh-radio-group-indicator-sizeindicatorblock-size
inline-size
default--xh-_radio-group-indicator
--xh-radio-group-item-bg-hoveritembackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-bg-subtle
--xh-radio-group-item-bg-presseditembackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-radio-group-item-description-fgitem-descriptioncolordefault--xh-fg-muted
--xh-radio-group-item-description-fg-disableditem
item-description
colordisabled--xh-fg-disabled
--xh-radio-group-item-description-font-sizeitem-descriptionfont-sizedefault--xh-text-secondary-size
--xh-radio-group-item-fgitemcolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-radio-group-item-fg-disableditemcolordisabled--xh-fg-disabled
--xh-radio-group-item-font-sizeitem
root
font-sizedefault
variant=segmented
--xh-_radio-group-font-size
--xh-radio-group-item-gapitem
root
gapdefault
variant=segmented
--xh-_radio-group-item-gap
--xh-radio-group-item-radiusitemborder-radiusdefault--xh-shape-control
--xh-radio-group-item-row-gapitemrow-gaphas(> [data-scope='radio-group'][data-part='item-description'])
not([data-xh-choice-card])
xh-choice-card
--xh-space-1
--xh-radio-group-label-fglabelcolordefault--xh-fg-muted
--xh-radio-group-label-fg-disabledlabel
root
colordisabled--xh-fg-subtle
--xh-radio-group-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-radio-group-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-radio-group-segment-bg-hoveritem
root
background-colordisabled
hover
not([data-disabled])
not([data-readonly])
not([data-state='checked'])
readonly
state=checked
variant=segmented
--xh-bg-subtle
--xh-radio-group-segment-bg-presseditem
root
background-colordisabled
is(:active, [data-pressed])
not([data-disabled])
not([data-readonly])
not([data-state='checked'])
pressed
readonly
state=checked
variant=segmented
--xh-bg-subtle-hover
--xh-radio-group-segment-fgitem
root
color@media print
state=checked
variant=segmented
--xh-fg-default
--xh-fg-muted
--xh-radio-group-segment-fg-checkeditem
root
colorstate=checked
variant=segmented
--xh-_radio-group-segment-fg-checked
--xh-radio-group-segment-fg-checked-disableditem
root
colordisabled
state=checked
variant=segmented
--xh-_radio-group-segment-fg-checked-disabled
--xh-radio-group-segment-fg-hoveritem
root
colordisabled
hover
not([data-disabled])
not([data-readonly])
not([data-state='checked'])
readonly
state=checked
variant=segmented
--xh-fg-default
--xh-radio-group-segment-font-weightitem
root
font-weightvariant=segmented--xh-text-label-weight
--xh-radio-group-segment-font-weight-checkeditem
root
font-weightstate=checked
variant=segmented
--xh-font-weight-medium
--xh-radio-group-segment-hitem
root
block-size
min-block-size
orientation=horizontal
variant=segmented
--xh-_radio-group-segment-h
--xh-radio-group-segment-pxitem
root
padding-inlinevariant=segmented--xh-_radio-group-segment-px
--xh-radio-group-segment-radiusitem
root
border-radiusvariant=segmented--xh-shape-inset
--xh-radio-group-segment-separatoritem
root
background-colororientation=horizontal
variant=segmented
--xh-border-default
--xh-radio-group-thumb-bgthumbbackgrounddefault--xh-_radio-group-thumb-bg
--xh-radio-group-thumb-bg-disabledroot
thumb
backgrounddisabled
has(> [data-scope='radio-group'][data-part='item'][data-state='checked'][data-disabled])
state=checked
variant=segmented
--xh-_radio-group-thumb-bg-disabled
--xh-radio-group-thumb-bg-hoverroot
thumb
backgrounddisabled
has(> [data-scope='radio-group'][data-part='item'][data-state='checked']:not([data-disabled])
hover
not([data-readonly])
readonly
state=checked
variant=segmented
--xh-_radio-group-thumb-bg-hover
--xh-radio-group-thumb-borderthumbborderdefaulttransparent
--xh-radio-group-thumb-radiusthumbborder-radiusdefault--xh-shape-inset
--xh-radio-group-thumb-shadowthumbbox-shadowdefaultnone
--xh-radio-group-track-bgrootbackgroundvariant=segmented--xh-bg-field
--xh-radio-group-track-bg-disabledrootbackgrounddisabled
variant=segmented
--xh-bg-muted
--xh-radio-group-track-borderrootbordervariant=segmented--xh-border-control
--xh-radio-group-track-border-invalidrootborder-colorinvalid
variant=segmented
--xh-border-invalid
--xh-radio-group-track-paddingitem
root
inset-block-start
min-block-size
padding
@media (pointer: coarse)
orientation=horizontal
variant=segmented
--xh-space-0_5
--xh-radio-group-track-radiusrootborder-radiusvariant=segmented--xh-shape-control

Released under The MIT License