UIComponentsReact
A year typed in one segment, a spinbutton, with a button that clears it.
Built on the headless Year Field.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/year-field.jsonIt also adds utils, button. The app needs its setup first: Installation.
Usage
Put a YearFieldInput and a YearFieldClear inside YearField, and a FieldLabel above it. Without children, YearFieldInput renders the segment, styled; pass your own children to place it yourself with YearFieldSegment. Values are strings such as 2026. The keys, the typing, the limits, the form value and the validity come from the headless Year Field.
import {
YearField,
YearFieldClear,
YearFieldInput,
YearFieldSegment,
} from '@/components/ui/year-field'Examples
Default
A birth year under its label, with a Clear button.
It looks as Date Field does: Input's box, the focused segment filled, an empty one dimmed to its placeholder and an invalid one underlined with a dashed line. This item takes Base UI's component ID as its slug and one name per Base UI part.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Year Field's API reference.