Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Year Field

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

year-field.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/year-field.json

It 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.

Its preview and code are at the top of the page.

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.