UIComponentsReact
A field the reader types a year into, with a button that opens a year calendar in a popup to pick it from.
Built on the headless Year Picker.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/year-picker.jsonIt also adds utils, button, year-calendar, popover. The app needs its setup first: Installation.
Usage
The parts are the Date Picker's for a year: YearPicker holds a YearPickerControl with YearPickerInput, YearPickerClear and YearPickerTrigger, and a YearPickerPortal with a YearPickerPositioner, a YearPickerPopup and a YearPickerCalendar. Name the control (aria-label, or a Field label around the picker). YearPickerPreset sets a year from a function of the current year and YearPickerClose closes the popup. The value is a '2026' string; min, max, isYearDisabled, isYearUnavailable, locale, yearsPerPage, closeOnSelect and the rest are the headless Year Picker's Root props.
import {
YearPicker,
YearPickerCalendar,
YearPickerClear,
YearPickerClose,
YearPickerControl,
YearPickerInput,
YearPickerPopup,
YearPickerPortal,
YearPickerPositioner,
YearPickerPreset,
YearPickerSegment,
YearPickerTrigger,
} from '@/components/ui/year-picker'Examples
Default
An input with the clear and calendar buttons beside it.
shadcn has no year picker. This item follows the Date Picker's composition with the Year Calendar's markup in the popup, so it differs from shadcn's date picker page in the same places.
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 Picker's API reference.