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

查看生态总览
Skip to content

TextField ​

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="text-field": root · label · control · prefix · input · suffix · clear-trigger · count

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-text-field>
Vue componentsXhTextFieldClearTrigger XhTextFieldControl XhTextFieldCount XhTextFieldInput XhTextFieldLabel XhTextFieldPrefix XhTextFieldRoot XhTextFieldSuffix
ComposableuseTextField
State machinetextFieldMachine
Skin@xihan-ui/styles/text-field.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuestring
defaultValuestring
typeTextFieldType
placeholderstring
disabledboolean
readOnlyboolean
requiredboolean
invalidboolean
namestring
maxLengthnumber
clearableboolean
showCountboolean
autoSizeboolean | TextFieldAutoSize
variantControlVariant
toneTone
sizeSize
translationsPartial<TextFieldTranslations>
onValueChange(details: TextFieldValueChangeDetails) => void
onClear() => void

Events ​

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

EventPayload
value-changeTextFieldValueChangeDetails
clear``

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhTextFieldCountdefaultTextFieldCountSlotProps
XhTextFieldRootdefaultTextFieldRootSlotProps
XhTextFieldRootlabel—

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
XhTextFieldCountchildrenSlotChildren<TextFieldCountSlotProps>
XhTextFieldInputasTextFieldInputHost
XhTextFieldRootlabelReactNode
XhTextFieldRootmultilineboolean
XhTextFieldRootchildrenSlotChildren<TextFieldRootSlotProps>

State ​

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · VALUE.CLEAR · FORM.RESET · PRESS.START · PRESS.END

Guards: canEdit · canClear

connect API ​

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

MemberType
valuestring
emptyboolean
disabledboolean
readOnlyboolean
invalidboolean
clearableboolean
atLimitboolean
countnumber
maxLengthnumber | undefined
showCountboolean
canClearboolean
setValue(next: string) => void
clear() => void
autoSizeboolean | TextFieldAutoSize
getRootProps() => T['element']
getControlProps() => T['element']
getLabelProps() => T['label']
getInputProps(props?: TextFieldInputProps) => T['input']
getPrefixProps() => T['element']
getSuffixProps() => T['element']
getClearTriggerProps() => T['button']
getCountProps() => 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
Escapetext-field.kbd.clear
Enter / Spacetext-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-readonly'true' | 'false'
inputaria-required'true' | 'false'
suffixaria-hidden'true'
clear-triggeraria-labellabel.clearTrigger
countaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/text-field.css is written against [data-scope="text-field"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-text-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-at-max'' (present only while the condition holds)
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
rootdata-variantprops.variant
labeldata-disabled'' (present only while the condition holds)
controldata-at-max'' (present only while the condition holds)
controldata-disabled'' (present only while the condition holds)
controldata-empty'' (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-at-max'' (present only while the condition holds)
inputdata-disabled'' (present only while the condition holds)
inputdata-empty'' (present only while the condition holds)
inputdata-invalid'' (present only while the condition holds)
inputdata-xh-field-auto-size'' (present only while the condition holds)
inputdata-xh-field-input''
inputdata-xh-field-layout'textarea' | 'single-line'
suffixdata-disabled'' (present only while the condition holds)
suffixdata-xh-field-affix'suffix'
clear-triggerdata-pressed'' (present only while the condition holds)
clear-triggerdata-xh-action-control''
clear-triggerdata-xh-action-display'has-value'
clear-triggerdata-xh-action-has-value'' (present only while the condition holds)
clear-triggerdata-xh-action-profile'field-inset'
clear-triggerdata-xh-action-sizeprops.size
clear-triggerdata-xh-action-variant'ghost'
countdata-at-max'' (present only while the condition holds)
countdata-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-text-field-action-bgclear-trigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-text-field-action-bg-activeclear-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-text-field-action-bg-hoverclear-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-text-field-action-fgclear-triggercolordefault--xh-fg-field-clear
--xh-text-field-action-fg-hoverclear-triggercolordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-fg-default
--xh-text-field-action-font-sizeclear-triggerfont-sizedefault--xh-_text-field-action-font-size
--xh-text-field-action-radiusclear-triggerborder-radiusdefault--xh-shape-circle
--xh-text-field-action-sizeclear-triggerblock-size
inline-size
min-inline-size
default
xh-action-profile=field-inset
--xh-_action-profile-visual-size
--xh-text-field-affix-fgprefix
suffix
colorxh-field-affix--xh-fg-muted
--xh-text-field-affix-fg-disabledprefix
suffix
colordisabled
xh-field-affix
--xh-fg-disabled
--xh-text-field-affix-font-sizeprefix
suffix
font-sizexh-field-affix--xh-_text-field-font-size
--xh-text-field-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-text-field-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-text-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-text-field-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-text-field-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-text-field-control-border-at-maxcontrolborder-colorat-max
invalid
not([data-invalid])
--xh-border-at-limit
--xh-text-field-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-text-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-text-field-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-text-field-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-text-field-control-gapcontrolgapxh-field-chrome--xh-_text-field-gap
--xh-text-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-_text-field-h
--xh-text-field-control-max-hinputmax-block-sizexh-field-auto-size--xh-viewport-h-sm
--xh-text-field-control-min-wcontrol
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-text-field-control-pxcontrolpadding-inlinexh-field-chrome--xh-_text-field-px
--xh-text-field-control-radiuscontrolborder-radiusxh-field-chrome--xh-shape-control
--xh-text-field-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-text-field-control-wrootinline-size
min-inline-size
default--xh-control-w
--xh-text-field-count-fgcountcolordefault--xh-fg-muted
--xh-text-field-count-fg-at-maxcountcolorat-max--xh-fg-warning
--xh-text-field-count-fg-disabledcountcolordisabled--xh-fg-disabled
--xh-text-field-count-font-sizecountfont-sizedefault--xh-_text-field-action-font-size
--xh-text-field-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-text-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-text-field-input-autofill-bginputbox-shadow-webkit-autofill
autofill
xh-field-input
--xh-bg-canvas
--xh-text-field-input-autofill-fginput-webkit-text-fill-color-webkit-autofill
autofill
xh-field-input
--xh-fg-default
--xh-text-field-input-fginputcolorxh-field-input--xh-fg-default
--xh-text-field-input-font-sizeinputfont-sizexh-field-input--xh-_text-field-font-size
--xh-text-field-input-max-hinputmax-block-sizexh-field-auto-size--xh-text-field-control-max-h
--xh-text-field-label-fglabelcolordefault--xh-fg-muted
--xh-text-field-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-text-field-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-text-field-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-text-field-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-text-field-placeholder-fginputcolorplaceholder
xh-field-input
--xh-fg-subtle
--xh-text-field-textarea-pyinputpadding-blockxh-field-input
xh-field-layout=textarea
--xh-space-1

Released under The MIT License