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

查看生态总览
Skip to content

DateField ​

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="date-field": root · label · control · segment-group · segment · clear-trigger · 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-date-field>
Vue componentsXhDateFieldClearTrigger XhDateFieldControl XhDateFieldHiddenInput XhDateFieldLabel XhDateFieldRoot XhDateFieldSegment XhDateFieldSegmentGroup
ComposableuseDateField
State machinedateFieldMachine
Skin@xihan-ui/styles/date-field.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuestring | null
defaultValuestring | null
minstring
maxstring
localestring
timeZonestring
granularityDateGranularity
hourCycleDateHourCycle
segmentsDateSegmentSet
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
namestring
placeholderstring | DateSegmentPlaceholders
translationsDateFieldTranslations
variantControlVariant
toneTone
sizeSize
onValueChange(details: DateFieldValueChangeDetails) => void
onClear() => void

Events ​

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

EventPayload
value-changeDateFieldValueChangeDetails
clear``

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhDateFieldRootdefaultDateFieldRootSlotProps
XhDateFieldRootlabel—
XhDateFieldSegmentdefaultDateFieldSegmentSlotProps

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
XhDateFieldRootlabelReactNode
XhDateFieldRootchildrenSlotChildren<DateFieldRootSlotProps>
XhDateFieldSegmentindexnumber | string
XhDateFieldSegmentsegmentDateSegmentType
XhDateFieldSegmentchildrenSlotChildren<DateFieldSegmentSlotProps>

State ​

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · VALUE.CLEAR · SEGMENT.STEP · SEGMENT.TYPE · SEGMENT.CLEAR · SEGMENT.PERIOD · SEGMENT.FOCUS · SEGMENT.BLUR · FORM.RESET · PRESS.START · PRESS.END

Guards: canEdit · canPress

connect API ​

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

MemberType
valuestring | null
valueAsDateDate | null
segmentsDateFieldSegmentState[]
completeboolean
emptyboolean
outOfRangeboolean
disabledboolean
readOnlyboolean
invalidboolean
focusedSegmentDateSegmentType | null
localestring
granularityDateGranularity
setValue(next: string | null) => void
clear() => void
canClearboolean
getRootProps() => T['element']
getLabelProps() => T['element']
getControlProps() => T['element']
getSegmentGroupProps() => T['element']
segmentOf(props: DateFieldSegmentProps) => DateFieldSegmentState | undefined
getSegmentProps(props: DateFieldSegmentProps) => T['element']
getClearTriggerProps() => T['button']
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
ArrowUpdate-field.kbd.increment
ArrowDowndate-field.kbd.decrement
ArrowRightdate-field.kbd.next
ArrowLeftdate-field.kbd.prev
Homedate-field.kbd.first
Enddate-field.kbd.last
Backspacedate-field.kbd.clear
0 / 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9date-field.kbd.digit
Enter / Spacedate-field.kbd.press
a / pdate-field.kbd.day-period

ARIA ​

These attributes are produced by connect.

PartAttributeValue
controlaria-disabled'true' | 'false'
controlaria-labelprops.ariaLabel
controlaria-labelledbyid of the label part | undefined
controlrole'group'
segmentaria-disabledundefined | 'true' | 'false'
segmentaria-invalidundefined | 'true' | 'false'
segmentaria-labelitem?.label
segmentaria-readonlyundefined | 'true' | 'false'
segmentaria-requiredundefined | 'true' | 'false'
segmentaria-valuemaxundefined | String(item.max)
segmentaria-valueminundefined | String(item.min)
segmentaria-valuenowundefined | String(item.value)
segmentaria-valuetextitem?.text
segmentroleundefined | 'spinbutton'
clear-triggeraria-labeltranslations.clearTrigger

Style reference ​

Skin ​

@xihan-ui/styles/date-field.css is written against [data-scope="date-field"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-date-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-complete'' (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-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
segment-groupdata-disabled'' (present only while the condition holds)
segment-groupdata-invalid'' (present only while the condition holds)
segment-groupdata-placeholder-shown'' (present only while the condition holds)
segment-groupdata-placeholder-textprops.placeholder | undefined
segment-groupdata-readonly'' (present only while the condition holds)
segmentdata-disabled'' (present only while the condition holds)
segmentdata-focus'' (present only while the condition holds)
segmentdata-indexString(index) | undefined
segmentdata-invalid'' (present only while the condition holds)
segmentdata-placeholder'' (present only while the condition holds)
segmentdata-readonly'' (present only while the condition holds)
segmentdata-segmentitem?.type
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'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-date-field-action-bgclear-trigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-date-field-action-bg-activeclear-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-date-field-action-bg-hoverclear-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-date-field-action-fgclear-triggercolordefault--xh-fg-field-clear
--xh-date-field-action-fg-hoverclear-triggercolordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-fg-default
--xh-date-field-action-font-sizeclear-triggerfont-sizedefault--xh-text-secondary-size
--xh-date-field-action-radiusclear-triggerborder-radiusdefault--xh-shape-circle
--xh-date-field-action-sizeclear-triggerblock-size
inline-size
min-inline-size
default
xh-action-profile=field-inset
--xh-_action-profile-visual-size
--xh-date-field-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-date-field-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-date-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-date-field-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-date-field-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-date-field-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-date-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-date-field-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-date-field-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-date-field-control-gapcontrolgapxh-field-chrome--xh-_date-field-gap
--xh-date-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-_date-field-control-h
--xh-date-field-control-min-wcontrol
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-date-field-control-pxcontrolpadding-inlinexh-field-chrome--xh-_date-field-control-px
--xh-date-field-control-radiuscontrolborder-radiusxh-field-chrome--xh-shape-control
--xh-date-field-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-date-field-control-wrootinline-size
min-inline-size
default--xh-control-w
--xh-date-field-font-sizecontrolfont-sizedefault--xh-_date-field-font-size
--xh-date-field-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-date-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-date-field-label-fglabelcolordefault--xh-fg-muted
--xh-date-field-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-date-field-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-date-field-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-date-field-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-date-field-literal-fgsegment-groupcolornot([data-scope])--xh-fg-subtle
--xh-date-field-placeholder-fgsegment
segment-group
colorplaceholder
placeholder-shown
--xh-fg-subtle
--xh-date-field-segment-bg-focussegmentbackgroundfocus
focus-visible
--xh-_date-field-segment-bg
--xh-date-field-segment-bg-invalid-focussegmentbackgroundfocus
invalid
is([data-focus], :focus-visible)
--xh-bg-subtle
--xh-date-field-segment-fg-focussegmentcolorfocus
focus-visible
placeholder
--xh-_date-field-segment-fg
--xh-date-field-segment-fg-invalidsegmentcolorinvalid--xh-fg-danger
--xh-date-field-segment-fg-invalid-focussegmentcolorfocus
invalid
is([data-focus], :focus-visible)
--xh-fg-danger
--xh-date-field-segment-pxsegmentpadding-inlinedefault--xh-space-0_5
--xh-date-field-segment-pysegmentpadding-blockdefault--xh-space-0
--xh-date-field-segment-radiussegmentborder-radiusdefault--xh-shape-inset

Released under The MIT License