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

查看生态总览
Skip to content

Field ​

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="field": root · label · control · description · error-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-field>
Vue componentsXhFieldBoundary XhFieldControl XhFieldDescription XhFieldErrorText XhFieldLabel XhFieldRoot
ComposableuseField
State machineNone: connect computes attributes from props directly
Skin@xihan-ui/styles/field.css

Props ​

PropTypeRequired
controlIdstring
disabledboolean
invalidboolean
partsFieldRenderedParts
readOnlyboolean
requiredboolean

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhFieldControldefaultFieldControlSlotProps
XhFieldRootdefault—
XhFieldRootlabel—
XhFieldRootcontrol—
XhFieldRootdescription—
XhFieldRooterrorText—

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
XhFieldBoundarychildrenReactNode
XhFieldControlasChildboolean
XhFieldControlchildrenSlotChildren<FieldControlSlotProps>
XhFieldRootlabelReactNode
XhFieldRootcontrolReactNode
XhFieldRootdescriptionReactNode
XhFieldRooterrorTextReactNode

connect API ​

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

MemberType
invalidboolean
requiredboolean
disabledboolean
readOnlyboolean
controlIdstring
labelIdstring
getRootProps() => T['element']
getLabelProps() => T['label']
getControlProps() => T['element']
getDescriptionProps() => T['element']
getErrorTextProps() => 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.

No keyboard interaction: the component takes no focus, or focus behavior comes entirely from native elements.

ARIA ​

These attributes are produced by connect.

PartAttributeValue
controlaria-describedby[ rendered?.description === false ? null : ids.descri…
controlaria-invalid'true' | 'false'
controlaria-labelledbyundefined | id of the label part
controlaria-readonly'true' | 'false'
controlaria-required'true' | 'false'
error-textaria-atomic'true'
error-textaria-live'polite'
error-textrole'status'

Style reference ​

Skin ​

@xihan-ui/styles/field.css is written against [data-scope="field"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-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-invalid'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
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-required'' (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-variant'outline'
controldata-xh-field-chrome''
controldata-xh-field-size'md'
descriptiondata-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-field-border-invalidjumperborder-coloruser-invalid--xh-_field-variant-border-invalid
--xh-field-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-field-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-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-field-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-field-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-field-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-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-field-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-field-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-field-control-font-sizecontrolfont-sizedefault--xh-text-body-size
--xh-field-control-hcontrol
label
root
block-size
min-block-size
padding-block
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'])
layout=horizontal
xh-field-chrome
xh-field-input
xh-field-layout=multi-tag
xh-field-layout=single-line
xh-field-layout=textarea
--xh-_field-size-control-height
--xh-control-h-md
--xh-field-control-pxcontrolpadding-inlinexh-field-chrome--xh-_field-size-padding-inline
--xh-field-control-radiuscontrolborder-radiusdefault--xh-shape-control
--xh-field-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-field-description-fgdescriptioncolordefault--xh-fg-subtle
--xh-field-description-fg-disableddescriptioncolordisabled--xh-fg-subtle
--xh-field-description-font-sizedescriptionfont-sizedefault--xh-text-caption-size
--xh-field-error-fgerror-textcolordefault--xh-fg-danger
--xh-field-error-font-sizeerror-text
root
block-size
font-size
margin-block-end
padding-block-end
default
has(> [data-scope='field'][data-part='error-text'][hidden])
not(:has(> [data-scope='field'][data-part='description']:not([hidden])
--xh-text-caption-size
--xh-field-gaplabel
root
gap
margin-block-end
default--xh-space-0
--xh-field-label-fglabelcolordefault--xh-fg-muted
--xh-field-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-field-label-fg-invalidlabelcolorinvalid--xh-fg-danger
--xh-field-label-font-sizelabel
root
font-size
padding-block
default
layout=horizontal
--xh-text-label-size
--xh-field-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-field-label-gaprootcolumn-gaplayout=horizontal--xh-space-4
--xh-field-label-gap-blocklabelmargin-block-enddefault--xh-space-2
--xh-field-label-leadinglabel
root
line-height
padding-block
layout=horizontal--xh-leading-normal
--xh-field-label-starlabelcolorrequired--xh-fg-danger

Released under The MIT License