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

查看生态总览
Skip to content

NumberField ​

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="number-field": root · label · control · prefix · input · suffix · increment-trigger · decrement-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-number-field>
Vue componentsXhNumberFieldControl XhNumberFieldDecrementTrigger XhNumberFieldIncrementTrigger XhNumberFieldInput XhNumberFieldLabel XhNumberFieldPrefix XhNumberFieldRoot XhNumberFieldSuffix
ComposableuseNumberField
State machinenumberFieldMachine
Skin@xihan-ui/styles/number-field.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuestring
defaultValuestring
minnumber
maxnumber
stepnumber
largeStepnumber
disabledboolean
readOnlyboolean
requiredboolean
invalidboolean
namestring
placeholderstring
changeDelaynumber
changeIntervalnumber
minChangeIntervalnumber
clampValueOnBlurboolean
variantControlVariant
toneTone
sizeSize
parse(text: string) => number
format(value: number) => string
onValueChange(details: NumberFieldValueChangeDetails) => void

Events ​

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

EventPayload
value-changeNumberFieldValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhNumberFieldRootdefaultNumberFieldRootSlotProps
XhNumberFieldRootlabel—

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
XhNumberFieldRootlabelReactNode
XhNumberFieldRootchildrenSlotChildren<NumberFieldRootSlotProps>

State ​

The following names are internal to the state machine.

States: idle · spinning

Events: VALUE.SET · VALUE.STEP · VALUE.TO_MIN · VALUE.TO_MAX · INPUT.BLUR · PRESS.START · PRESS.END · after.changeInterval · FORM.RESET · TRIGGER.PRESS.START · TRIGGER.PRESS.END

Guards: canStep · canPressTrigger

connect API ​

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

MemberType
valuestring
valueAsNumbernumber
emptyboolean
disabledboolean
readOnlyboolean
invalidboolean
canIncrementboolean
canDecrementboolean
outOfRangeboolean
setValue(next: string) => void
increment() => void
decrement() => void
getRootProps() => T['element']
getLabelProps() => T['label']
getControlProps() => T['element']
getPrefixProps() => T['element']
getInputProps() => T['input']
getSuffixProps() => T['element']
getIncrementTriggerProps() => T['button']
getDecrementTriggerProps() => T['button']

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
ArrowUpnumber-field.kbd.increment
ArrowDownnumber-field.kbd.decrement
PageUpnumber-field.kbd.large-increment
PageDownnumber-field.kbd.large-decrement
Homenumber-field.kbd.min
Endnumber-field.kbd.max
Enter / Spacenumber-field.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
prefixaria-hidden'true'
inputaria-invalid'true' | 'false'
inputaria-labelprops.ariaLabel
inputaria-labelledbyid of the label part | undefined
inputaria-valuemaxprops.max
inputaria-valueminprops.min
inputaria-valuenowundefined | decodeNumber(value, { parse: prop('parse'), format: p…
inputrole'spinbutton'
suffixaria-hidden'true'
increment-triggeraria-hidden'true'
decrement-triggeraria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/number-field.css is written against [data-scope="number-field"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-number-field 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-out-of-range'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
rootdata-variantprops.variant
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)
controldata-variantprops.variant
controldata-xh-action-owner''
controldata-xh-field-chrome''
controldata-xh-field-sizeprops.size
prefixdata-disabled'' (present only while the condition holds)
prefixdata-xh-field-affix'prefix'
inputdata-disabled'' (present only while the condition holds)
inputdata-invalid'' (present only while the condition holds)
inputdata-readonly'' (present only while the condition holds)
inputdata-xh-field-input''
inputdata-xh-field-layout'single-line'
suffixdata-disabled'' (present only while the condition holds)
suffixdata-xh-field-affix'suffix'
increment-triggerdata-disabled'' (present only while the condition holds)
increment-triggerdata-pressed'' (present only while the condition holds)
increment-triggerdata-xh-action-control''
increment-triggerdata-xh-action-display'hover-focus'
increment-triggerdata-xh-action-profile'field-inset'
increment-triggerdata-xh-action-sizeprops.size
increment-triggerdata-xh-action-variant'ghost'
decrement-triggerdata-disabled'' (present only while the condition holds)
decrement-triggerdata-pressed'' (present only while the condition holds)
decrement-triggerdata-xh-action-control''
decrement-triggerdata-xh-action-display'hover-focus'
decrement-triggerdata-xh-action-profile'field-inset'
decrement-triggerdata-xh-action-sizeprops.size
decrement-triggerdata-xh-action-variant'ghost'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-number-field-affix-fgprefix
suffix
colorxh-field-affix--xh-fg-muted
--xh-number-field-affix-fg-disabledprefix
suffix
colordisabled
xh-field-affix
--xh-fg-disabled
--xh-number-field-affix-font-sizeprefix
suffix
font-sizexh-field-affix--xh-_number-field-font-size
--xh-number-field-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-number-field-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-number-field-control-bg-hovercontrolbackground-colordisabled
hover
invalid
loading
not(:focus-within)
not([data-disabled])
not([data-invalid])
not([data-loading])
not([data-readonly])
readonly
xh-field-chrome
--xh-_field-variant-bg-hover
--xh-number-field-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-number-field-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-number-field-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-number-field-control-border-hovercontrolborder-colordisabled
hover
invalid
loading
not(:focus-within)
not([data-disabled])
not([data-invalid])
not([data-loading])
not([data-readonly])
readonly
xh-field-chrome
--xh-_field-variant-border-hover
--xh-number-field-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-number-field-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-number-field-control-gapcontrolgapxh-field-chrome--xh-_number-field-gap
--xh-number-field-control-hcontrolblock-size
min-block-size
has([data-xh-field-input][data-xh-field-layout='multi-tag'])
has([data-xh-field-input][data-xh-field-layout='single-line'])
has([data-xh-field-input][data-xh-field-layout='textarea'])
xh-field-chrome
xh-field-input
xh-field-layout=multi-tag
xh-field-layout=single-line
xh-field-layout=textarea
--xh-_number-field-h
--xh-number-field-control-min-wcontrol
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-number-field-control-pxcontrolpadding-inlinexh-field-chrome0
--xh-number-field-control-radiuscontrolborder-radiusxh-field-chrome--xh-shape-control
--xh-number-field-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-number-field-control-wrootinline-size
min-inline-size
default--xh-control-w
--xh-number-field-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-number-field-icon-sizecontrol
root
--xh-icon-sizedefault
size=lg
size=sm
xh-field-chrome
--xh-_field-size-glyph-size
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-number-field-input-aligncontrol
input
text-aligndefaultstart
--xh-number-field-input-autofill-bgcontrol
input
box-shadow-webkit-autofill
autofill
xh-field-input
--xh-bg-canvas
--xh-number-field-input-autofill-fgcontrol
input
-webkit-text-fill-color-webkit-autofill
autofill
xh-field-input
--xh-fg-default
--xh-number-field-input-fgcontrol
input
colorxh-field-input--xh-fg-default
--xh-number-field-input-font-sizecontrol
input
font-sizexh-field-input--xh-_number-field-font-size
--xh-number-field-input-pxcontrol
input
padding-inlinedefault--xh-_number-field-px
--xh-number-field-input-wcontrol
input
inline-sizedefault5em
--xh-number-field-label-fglabelcolordefault--xh-fg-muted
--xh-number-field-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-number-field-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-number-field-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-number-field-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-number-field-placeholder-fgcontrol
input
colorplaceholder
xh-field-input
--xh-fg-subtle
--xh-number-field-stepper-bgcontrol
decrement-trigger
increment-trigger
--xh-ink-surface
background-color
@media (hover: hover) and (pointer: fine)
disabled
xh-ink-surface
--xh-bg-subtle
--xh-number-field-stepper-bg-hovercontrol
decrement-trigger
increment-trigger
background-color@media (hover: hover) and (pointer: fine)
disabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-bg-subtle-hover
--xh-number-field-stepper-insetcontrol
decrement-trigger
increment-trigger
block-size
inset-block-end
inset-block-start
inset-inline-end
padding-inline-end
@media (hover: hover) and (pointer: fine)
has([data-part='increment-trigger'], [data-part='decrement-trigger'])
--xh-_number-field-stepper-inset
--xh-number-field-stepper-wcontrol
decrement-trigger
increment-trigger
inline-size
padding-inline-end
@media (hover: hover) and (pointer: fine)
has([data-part='increment-trigger'], [data-part='decrement-trigger'])
--xh-control-indicator-lg
--xh-number-field-trigger-bg-activecontrol
decrement-trigger
increment-trigger
background-color@media (hover: hover) and (pointer: fine)
disabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-bg-subtle-active
--xh-number-field-trigger-fgcontrol
decrement-trigger
increment-trigger
colordefault--xh-fg-muted
--xh-number-field-trigger-fg-hovercontrol
decrement-trigger
increment-trigger
colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-fg-default
--xh-number-field-trigger-font-sizecontrol
decrement-trigger
increment-trigger
font-sizedefault--xh-_number-field-trigger-font-size
--xh-number-field-trigger-radiuscontrol
decrement-trigger
increment-trigger
border-radiusdefault--xh-shape-inset
--xh-number-field-trigger-sizecontrol
decrement-trigger
increment-trigger
block-size
inline-size
min-inline-size
default
xh-action-profile=field-inset
--xh-_action-profile-visual-size

Released under The MIT License