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

查看生态总览
Skip to content

Rating ​

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="rating": root · label · control · value-text · 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-rating>
Vue componentsXhRatingControl XhRatingHiddenInput XhRatingItem XhRatingLabel XhRatingRoot XhRatingValueText
ComposableuseRating
State machineratingMachine
Skin@xihan-ui/styles/rating.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuenumber
defaultValuenumber
countnumber
allowHalfboolean
allowClearboolean
disabledboolean
readOnlyboolean
requiredboolean
invalidboolean
namestring
dirDirection
toneTone
sizeSize
translationsPartial<RatingTranslations>
onValueChange(details: RatingValueChangeDetails) => void
onHoverChange(details: RatingHoverChangeDetails) => void

Events ​

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

EventPayload
value-changeRatingValueChangeDetails
hover-changeRatingHoverChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhRatingItemdefaultRatingItemSlotProps
XhRatingRootdefaultRatingRootSlotProps
XhRatingRootlabel—

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
XhRatingItemvaluenumber | stringYes
XhRatingItemchildrenSlotChildren<RatingItemSlotProps>
XhRatingRootlabelReactNode
XhRatingRootchildrenSlotChildren<RatingRootSlotProps>

State ​

Public state is written to data-state.

PartValues
item'checked' | 'unchecked'

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · VALUE.STEP · VALUE.TO_MIN · VALUE.TO_MAX · ITEM.SELECT · ITEM.FOCUS · ITEM.HOVER · HOVER.CLEAR · CONTROL.BLUR · FORM.RESET · PRESS.START · PRESS.END

Guards: canInteract

connect API ​

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

MemberType
valuenumber
hoveredValuenumber | null
highlightedValuenumber
valueTextstring
countnumber
emptyboolean
disabledboolean
readOnlyboolean
invalidboolean
itemsreadonly number[]
getItemState(props: RatingItemProps) => RatingItemState
setValue(next: number) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getControlProps() => T['element']
getValueTextProps() => T['element']
getItemProps(props: RatingItemProps) => T['element']
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+Tabrating.kbd.tab
ArrowRight / ArrowUprating.kbd.increment
ArrowLeft / ArrowDownrating.kbd.decrement
Homerating.kbd.min
Endrating.kbd.max

ARIA ​

These attributes are produced by connect.

PartAttributeValue
controlaria-disabled'true' | 'false'
controlaria-invalid'true' | 'false'
controlaria-labelprops.ariaLabel
controlaria-labelledbyid of the label part | undefined
controlaria-orientation'horizontal'
controlaria-readonly'true' | 'false'
controlaria-required'true' | 'false'
controlrole'radiogroup'
value-textaria-hidden'true'
itemaria-checked'true' | 'false'
itemaria-disabled'true' | 'false'
itemaria-labelundefined | itemLabel(item.value, count)
itemaria-posinsetitem.value
itemaria-setsizeratingMax(prop('count'))
itemrole'radio'
hidden-inputaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/rating.css is written against [data-scope="rating"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-rating 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-empty'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
labeldata-disabled'' (present only while the condition holds)
controldata-disabled'' (present only while the condition holds)
controldata-invalid'' (present only while the condition holds)
controldata-readonly'' (present only while the condition holds)
value-textdata-disabled'' (present only while the condition holds)
value-textdata-empty'' (present only while the condition holds)
value-textdata-invalid'' (present only while the condition holds)
value-textdata-readonly'' (present only while the condition holds)
itemdata-disabled'' (present only while the condition holds)
itemdata-half'' (present only while the condition holds)
itemdata-highlighted'' (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-control''
itemdata-xh-action-display'always'
itemdata-xh-action-profile'icon'
itemdata-xh-action-size'xs'
itemdata-xh-action-variant'ghost'
hidden-inputdata-disabled'' (present only while the condition holds)

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-rating-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-rating-item-bg-presseditembackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-rating-item-fgitembackground-color
background-image
color
default
disabled
empty
focus-visible
half
hover
is(:active, [data-pressed])
loading
not(:empty)
not([data-disabled])
not([data-loading])
pressed
--xh-fg-subtle
--xh-rating-item-fg-highlighteditembackground-color
background-image
color
@media print
disabled
empty
focus-visible
half
highlighted
hover
is(:active, [data-pressed])
loading
not(:empty)
not([data-disabled])
not([data-loading])
pressed
--xh-_rating-accent
--xh-rating-item-fg-invaliditembackground-color
color
disabled
empty
focus-visible
hover
invalid
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-border-invalid
--xh-rating-item-font-sizeitem
root
--xh-icon-size
font-size
default--xh-_rating-item-size
--xh-rating-item-gapcontrolgapdefault--xh-_rating-item-gap
--xh-rating-item-radiusitemborder-radiusdefault--xh-shape-control
--xh-rating-label-fglabelcolordefault--xh-fg-muted
--xh-rating-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-rating-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-rating-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-rating-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-rating-value-text-fgvalue-textcolordefault--xh-fg-muted
--xh-rating-value-text-fg-disabledvalue-textcolordisabled--xh-fg-subtle
--xh-rating-value-text-font-sizevalue-textfont-sizedefault--xh-_rating-font-size

Released under The MIT License