Skip to content

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

InputsReact

Month Picker

A MonthField with a month grid in a popup: the field is the primary input, a trigger button opens a dialog that holds a MonthCalendar, and both edit one value, an HTML month string such as '2026-11'.

Rendered by React 19.3.1

Loading React…
import { Field } from '@hamur/react/field'
import { MonthCalendar } from '@hamur/react/month-calendar'
import { MonthPicker } from '@hamur/react/month-picker'

export default function MonthPickerExample() {
  return (
    <Field.Root name="statement" className="field">
      <Field.Label>Statement month</Field.Label>
      <MonthPicker.Root locale="en-US" today="2026-11-07">
        <MonthPicker.Control className="date-field date-picker-control">
          <MonthPicker.Input className="date-field-input">
            {({ segments }) =>
              segments.map((segment) => (
                <MonthPicker.Segment
                  key={segment.index}
                  segment={segment}
                  className="date-field-segment"
                />
              ))
            }
          </MonthPicker.Input>
          <MonthPicker.Clear className="date-field-clear">
            ×
          </MonthPicker.Clear>
          <MonthPicker.Trigger className="date-picker-trigger">
            <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
              <path d="M2.5 3.5h11v10h-11zM2.5 6.5h11M5.5 1.5v3M10.5 1.5v3" />
            </svg>
          </MonthPicker.Trigger>
        </MonthPicker.Control>
        <MonthPicker.Portal>
          <MonthPicker.Positioner sideOffset={8}>
            <MonthPicker.Popup className="popover date-picker-popup">
              <MonthPicker.Calendar className="calendar">
                <div className="calendar-header">
                  <MonthCalendar.PrevButton className="calendar-nav">‹</MonthCalendar.PrevButton>
                  <div className="calendar-caption">
                    <MonthCalendar.Heading className="calendar-heading" />
                    <MonthCalendar.ViewTrigger className="calendar-view-trigger">
                      <svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true">
                        <path d="M2.5 4.5 6 8l3.5-3.5" />
                      </svg>
                    </MonthCalendar.ViewTrigger>
                  </div>
                  <MonthCalendar.NextButton className="calendar-nav">›</MonthCalendar.NextButton>
                </div>
                <MonthCalendar.MonthGrid className="calendar-grid">
                  {(grid) => (
                    <MonthCalendar.GridBody>
                      {grid.rows.map((row, index) => (
                        <MonthCalendar.GridRow key={index}>
                          {row.map((cell) => (
                            <MonthCalendar.Cell
                              key={cell.month}
                              month={cell.month}
                              className="calendar-cell calendar-period-cell"
                            >
                              <MonthCalendar.Month className="calendar-period" />
                            </MonthCalendar.Cell>
                          ))}
                        </MonthCalendar.GridRow>
                      ))}
                    </MonthCalendar.GridBody>
                  )}
                </MonthCalendar.MonthGrid>
                <MonthCalendar.YearGrid className="calendar-grid">
                  {(grid) => (
                    <MonthCalendar.GridBody>
                      {grid.rows.map((row, index) => (
                        <MonthCalendar.GridRow key={index}>
                          {row.map((cell) => (
                            <MonthCalendar.Cell
                              key={cell.year}
                              year={cell.year}
                              className="calendar-cell calendar-period-cell"
                            >
                              <MonthCalendar.Year className="calendar-period" />
                            </MonthCalendar.Cell>
                          ))}
                        </MonthCalendar.GridRow>
                      ))}
                    </MonthCalendar.GridBody>
                  )}
                </MonthCalendar.YearGrid>
              </MonthPicker.Calendar>
              <MonthPicker.Close className="button date-picker-close">
                Close
              </MonthPicker.Close>
            </MonthPicker.Popup>
          </MonthPicker.Positioner>
        </MonthPicker.Portal>
      </MonthPicker.Root>
    </Field.Root>
  )
}
Not measured yetTests passing in React
90.1 KiBSize
Not measured yetMemory
Not measured yetSpeed
[N] commits

Installation

npm i @hamur/react

Not on npm yet. The package goes out under the chosen name.

Anatomy

Import the component and assemble its parts:

<MonthPicker.Root>
  <MonthPicker.Control>
    <MonthPicker.Input>
      <MonthPicker.Segment />
    </MonthPicker.Input>
    <MonthPicker.Clear />
    <MonthPicker.Trigger />
  </MonthPicker.Control>
  <MonthPicker.Portal>
    <MonthPicker.Positioner>
      <MonthPicker.Popup>
        <MonthPicker.Calendar />
        <MonthPicker.Close />
      </MonthPicker.Popup>
    </MonthPicker.Positioner>
  </MonthPicker.Portal>
</MonthPicker.Root>

// Not in this example: MonthPicker.Preset

Examples

The demo at the top is the one example this component has so far.

API reference

66 props across 12 parts, in React syntax. className, style, render are listed once, under Shared props.

CalendarMonthPicker.Calendar

The calendar of the popup: Calendar.Root (or RangeCalendar.Root) wired to the picker's value, limits, locale and visible month. Compose it with the Calendar parts (Calendar.PrevButton, Calendar.Heading, Calendar.Grid and the rest). It takes no part in the Field: the control already submits and validates the value. Renders a <div>.

ClearMonthPicker.Clear

Clears the whole value, including a partly typed one. It is out of the tab order: Backspace clears a segment from the keyboard. Renders a <button>.

CloseMonthPicker.Close

A button that closes the popover. Renders a <button>.

Close props
PropTypeDefault
nativeButtonWhether the component renders a native <button> element when replacing itbooleantrue

ControlMonthPicker.Control

The group that holds the field and the trigger, and the element the popup is anchored to. It is the field's root: it is named by the Field label, shows the Field's validity, and counts the popup as inside it, so moving focus into the calendar neither touches nor validates the field. Renders a <div>.

InputMonthPicker.Input

The visual control: it wraps the segments. Its children are a function of the segments, since their order depends on the locale; without children it renders every segment. Renders a <div>.

Input props
PropTypeDefault
childrenThe segments, or a function of them: ({ segments }) => ....React.ReactNode | ((context: { segments: FieldSegment[]; }) => React.ReactNode)—

PopupMonthPicker.Popup

The dialog that holds the calendar and the presets. It is named "Choose date" unless you name it. Focus moves to the highlighted day when it opens, and returns to the trigger (or to the segment Alt+Down was pressed on) when it closes. Renders a <div>.

Popup props
PropTypeDefault
initialFocusDetermines the element to focus when the popover is opened.boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)—
finalFocusDetermines the element to focus when the popover is closed.boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)—

PortalMonthPicker.Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div>.

Portal props
PropTypeDefault
keepMountedWhether to keep the portal mounted in the DOM while the popup is hidden.booleanfalse
containerA parent element to render the portal element into.HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null—

PositionerMonthPicker.Positioner

Positions the popup against the control (the field and the trigger together). Renders a <div>.

Positioner props
PropTypeDefault
alignHow to align the popup relative to the specified side.Align'start'
anchorAn element to position the popup against.Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null—
positionMethodDetermines which CSS position property to use."absolute" | "fixed"'absolute'
sideWhich side of the anchor element to align the popup against.Side'bottom'
sideOffsetDistance between the anchor and the popup in pixels.number | OffsetFunction0
alignOffsetAdditional offset along the alignment axis in pixels.number | OffsetFunction0
collisionBoundaryAn element or a rectangle that delimits the area that the popup is confined to.Boundary'clipping-ancestors'
collisionPaddingAdditional space to maintain from the edge of the collision boundary.Padding5
stickyWhether to maintain the popup in the viewport afterbooleanfalse
arrowPaddingMinimum distance to maintain between the arrow and the edges of the popup.number5
disableAnchorTrackingWhether to disable the popup from tracking any layout shift of its positioning anchor.booleanfalse
collisionAvoidanceDetermines how to handle collisions when positioning the popup.CollisionAvoidance—

PresetMonthPicker.Preset

A button that sets the value to a date or a range, such as "Last 7 days". The value can be a function of today, which the picker reads from the clock after mount (or from today). It closes the popup like a day does. Renders a <button>.

Preset props
PropTypeDefault
valuerequiredThe value the preset sets, in the picker's unit: a date ('2026-11-07'), a month ('2026-11')DatePickerUnitPreset—
nativeButtonWhether the component renders a native <button> element when replacing itbooleantrue

RootMonthPicker.Root

Groups all parts of a field with a calendar popup that picks one month. It renders no element. Values are month strings such as '2026-11'; onValueChange is called only with a complete month, or null.

Root props
PropTypeDefault
openWhether the popup is open.boolean—
defaultOpenWhether the popup is initially open.booleanfalse
onOpenChangeEvent handler called when the popup opens or closes.((open: boolean, eventDetails: DatePickerRootOpenChangeEventDetails) => void)—
onOpenChangeCompleteEvent handler called after any animations complete when the popup opens or closes.((open: boolean) => void)—
actionsRefA ref to imperative actions: unmount and close.React.RefObject<PopoverRootActions | null>—
modalWhether the rest of the page is inert while the popup is open.boolean | "trap-focus"false
closeOnSelectWhether choosing a day (the second end of a range) or a preset closes the popup.booleantrue
localeThe BCP 47 locale of the field and the calendar.string'en-US'
timeZoneThe time zone that decides what today is, when today is not given.string—
labelsThe texts the picker, the field and the calendar add (the trigger and popup names, the ClosePartial<DatePickerLabels & DateFieldLabels & CalendarLabels>—
forceLeadingZerosWhether the day, month and hour show a leading zero.boolean—
placeholderValueThe value an empty segment takes on its first Up or Down press.string—
autoAdvanceWhether focus moves to the next segment when the typed number cannot get another digit.booleantrue
segmentRoleThe role of the segments.DateFieldSegmentRole'spinbutton'
onIncompleteChangeEvent handler called when the segments change while no complete value exists.((parts: FieldParts, eventDetails: any) => void)—
disabledWhether the component should ignore user interaction.booleanfalse
readOnlyWhether the user should be unable to change the value.booleanfalse
requiredWhether the user must fill in the field before submitting a form.booleanfalse
invalidWhether the field is invalid.booleanfalse
formIdentifies the form that owns the hidden inputs.string—
inputRefA ref to access the first segment.React.Ref<HTMLInputElement>—
childrenReact.ReactNode—
minThe earliest value that can be chosen: a date, a month or a year.`${number}` | `${number}-${number}-${number}` | `${number}-${number}`—
maxThe latest value that can be chosen: a date, a month or a year.`${number}` | `${number}-${number}-${number}` | `${number}-${number}`—
todayThe date of today, for the calendar and the presets.`${number}-${number}-${number}` | `${number}-${number}`—
visibleYearThe first visible year (a year picker's first year of the page).`${number}` | null—
defaultVisibleYearThe first visible year when initially rendered.`${number}`—
onVisibleYearChangeEvent handler called when the visible year changes.((year: `${number}`, eventDetails: DatePickerVisibleYearChangeEventDetails) => void)—
columnsThe number of cells in a row of the calendar's grids.number4
yearsPerPageThe number of years a year grid shows.number12
nameIdentifies the field when a form is submitted.string—
isMonthUnavailableWhether a month cannot be chosen but can hold focus.((month: `${number}-${number}`, anchor: `${number}-${number}` | null) => boolean)—
isMonthDisabledWhether a month is skipped by navigation and cannot be chosen.((month: `${number}-${number}`) => boolean)—
visibleYearsThe number of years shown side by side.number1
pageBehaviorWhether Previous and Next move by every visible year or by one.CalendarPageBehavior'visible'
viewThe view the calendar shows."month" | "year"—
defaultViewThe view the calendar shows when the popup opens, and returns to after it closes."month" | "year"'month'
onViewChangeEvent handler called when the view changes: a ViewTrigger press, a press on a year, or the((view: "month" | "year", eventDetails: DatePickerViewChangeEventDetails) => void)—
viewsThe views the user can reach, in any order.readonly ("month" | "year")[]—
valueThe month, null for none.`${number}-${number}` | null—
defaultValueThe month when initially rendered.`${number}-${number}` | null—
onValueChangeEvent handler called when the month changes: a complete month, or null.((value: `${number}-${number}` | null, eventDetails: DatePickerUnitChangeEventDetails) => void)—
autoComplete'bday' gives the segments the bday-month and bday-year autocomplete tokens, 'cc-exp'"off" | "cc-exp" | "bday"'off'

SegmentMonthPicker.Segment

One segment of the value. An editable segment (year, month, day, hour, minute, second, millisecond, day period) is a real <input> with the spinbutton role; a literal (/, :) is a <span> hidden from assistive technology., or a <span> for a literal. Renders an <input>.

Segment props
PropTypeDefault
segmentrequiredThe segment to render, one of the segments the Input gives its children.FieldSegment—

TriggerMonthPicker.Trigger

A button that opens the popup. It is named "Choose date", or "Change date, Saturday, November 7, 2026" once a date is chosen. It sits inside the control. Renders a <button>.

Trigger props
PropTypeDefault
nativeButtonWhether the component renders a native <button> element when replacing itbooleantrue
idID of the trigger.string—

Shared props

Every part that renders an element takes these.

Shared props
PropType
classNameCSS class applied to the element, or a function that returns a class based on the component's state.string | ((state: State) => string | undefined)
styleStyle applied to the element, or a function that returns a style object based on the component's state.React.CSSProperties | ((state: State) => React.CSSProperties | undefined)
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State>

Keyboard and accessibility

Keyboard

Keyboard
KeysDoesPart
EnterSpaceOn the trigger: opens the popup with focus on the value's month, else this monthTrigger
AltArrowDownOn a segment: opens the popup; closing returns focus to that segmentSegment
EnterSpaceOn a month: commits it, closes the popup and returns focus to the triggerPopup
EnterSpaceOn the caption button: shows the years; a year shows its months, the popup stays openCalendar
EscapeCloses the popup from either view and returns focus to the triggerPopup

Accessibility

What the parts set
PartSetsSo that
Controlrole="group" named by the Field label; the Field's validitythe field is announced once, "Statement month, group"
Triggeraria-haspopup="dialog", aria-expanded; aria-label "Choose month" or "Change month, December 2026"the button says what it does and what the month is now
Popuprole="dialog" named "Choose month"; aria-modal only with modalthe dialog is announced on open
Closea button, "Close"a touch screen reader can leave a popup it cannot Escape

Focus order

  1. The month and year segments, then the Trigger; Clear is out of the order. Nothing takes focus on mount.
  2. Opening moves focus to the month in the grid; the caption button and Close come in DOM order around it.
  3. Closing returns focus to the trigger, or to the segment the popup was opened from.