Skip to content

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

UIComponentsReact

Month Field

A month and a year typed in segments, in the order of the locale, each one a spinbutton, with a button that clears them both.

Built on the headless Month Field.See its API in Docs

Rendered by React 19.3.1

month-field.tsx

Installation

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

It also adds utils, button. The app needs its setup first: Installation.

Usage

Put a MonthFieldInput and a MonthFieldClear inside MonthField, and a FieldLabel above it. Without children, MonthFieldInput renders every segment, in the locale's order and styled; pass your own children to place them yourself, drawing each with MonthFieldSegment. Values are strings such as 2026-11, reported only once both segments are filled. The keys, the typing, the limits, the form value and the validity come from the headless Month Field.

import {
  MonthField,
  MonthFieldClear,
  MonthFieldInput,
  MonthFieldSegment,
} from '@/components/ui/month-field'

Examples

Default

A card expiry 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 Month Field's API reference.