|Kit

MonthPicker & YearPicker

A month or a year as the value — DatePicker and Calendar pinned to their month or year grid, single or range, with the same bounds, predicates, presets and locale.

MonthPicker and YearPicker commit a whole month or a whole year: a reporting month, a cohort's start year. They are DatePicker pinned to its month or year grid, the same way DateRangePicker pins range, so the trigger, popover, presets, withConfirm and clearable all work the same. MonthCalendar and YearCalendar are the inline forms, pinned over Calendar.

import { MonthPicker, YearPicker } from '@42-central/ui-react/date-picker';

<MonthPicker label="Reporting month" value={month} onChange={setMonth} />
<YearPicker label="Cohort start year" value={year} onChange={setYear} />

Playground

Component

Loading preview

Modes

Props

Code

<Component />

The value

The value is a native Date, like every other date component in the kit: the first day of the picked month (or January 1st of the picked year), at midnight in the picker's timeZone. Under range it is { start, end }, each end the first day of its month or year — so a March–June range ends on June 1st. Use endOfMonth from @internationalized/date, or new Date(y, m + 1, 0), when a query needs the inclusive last day.

A value or defaultValue that falls mid-month is shown as its month, and the next pick comes back on the first day. Pick a month below and watch what onChange hands back:

month = 2013-07-01 · period = { null → null }

Code

const [month, setMonth] = useState<Date | null>(new Date(2013, 6, 1));
const [period, setPeriod] = useState<DateRangeValue>({ start: null, end: null });

<MonthPicker label="Reporting month" value={month} onChange={setMonth} />
<MonthPicker label="Period" range value={period} onChange={setPeriod} />

Month

The popover opens on the month grid. The header steps a year at a time; click it to climb to the year grid and jump further.

Year

YearPicker opens on a decade, and stops there: its header pages decades but doesn't climb.

Range

range selects a { start, end } pair: click the first month (or year), then the last.

import { MonthPicker, type DateRangeValue } from '@42-central/ui-react/date-picker';

const [period, setPeriod] = useState<DateRangeValue>({ start: null, end: null });

<MonthPicker range value={period} onChange={setPeriod} />

Inline

MonthCalendar and YearCalendar are the same grids without a trigger — the Calendar / DatePicker split, from @42-central/ui-react/calendar.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019

Code

<MonthCalendar defaultValue={new Date(2013, 6, 1)} />
<YearCalendar defaultValue={new Date(2013, 0, 1)} />

Restricting selection

min and max widen to the whole month or year they fall in, so min={new Date(2026, 2, 15)} keeps March open. Here the window is March 2013 – February 2014.

<MonthPicker
  label="Reporting month"
  defaultValue={new Date(2013, 6, 1)}
  min={new Date(2013, 2, 15)}
  max={new Date(2014, 1, 10)}
/>

isDateUnavailable is asked about each month or year cell, with that unit's first day and a third argument naming the unit ("month" or "year"). The kit's predicate helpers compare at that unit: disablePast() closes every month before the current one but keeps the current month, beforeDate(d) / afterDate(d) keep d's own month, disableDates([...]) closes the months holding those days, and the day-only disableWeekends() closes nothing.

<MonthPicker label="Next review" isDateUnavailable={disablePast()} />
<YearPicker label="Graduation year" isDateUnavailable={disablePast()} />

A predicate of your own can read the unit too — here, no August reviews:

<MonthPicker isDateUnavailable={(date, _zone, unit) => unit === 'month' && date.getMonth() === 7} />

Presets

presets works as on DatePicker. presets={true} ships a set made for the unit, labelled by Intl.RelativeTimeFormat in the active locale:

Singlerange
MonthPickerThis month, Last month, Next monthThis year, Last year (as month spans), All time
YearPickerThis year, Last year, Next yearThis year, Last year, All time

A custom list uses DatePicker's { date } / { range } shapes; every date snaps to its month or year, so { range: { start: new Date(2013, 0, 1), end: new Date(2013, 2, 31) } } is a quarter.

const quarters: DatePreset[] = [
  { label: 'Q1 2013', range: { start: new Date(2013, 0, 1), end: new Date(2013, 2, 31) } },
  { label: 'Q2 2013', range: { start: new Date(2013, 3, 1), end: new Date(2013, 5, 30) } },
  // …
];

<MonthPicker label="Quarter" range presets={quarters} />

Locale & translations

Month names, the header and the trigger text ("July 2013", "juillet 2013", "2013") come from Intl in the active locale and the picker's timeZone; nothing is hardcoded. The placeholder defaults to "Pick a month" / "Pick a year" — pass placeholder to localize it. translations covers the rest, as on DatePicker: Ark's accessible names (prev/next, the header), Cancel/Apply, and preset labels by id — thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, allTime.

<MonthPicker label="Mois" locale="fr-FR" placeholder="Choisir un mois" presets defaultValue={new Date(2013, 6, 1)} />
<MonthPicker
  locale="fr-FR"
  placeholder="Choisir un mois"
  presets
  translations={{ presets: { allTime: 'Toujours' }, prevTrigger: () => 'Précédent' }}
/>

Right-to-left locales mirror the grid, the arrow keys and the header chevrons, as on Calendar.

Forms

name adds a hidden input serialized as YYYY-MM (the <input type="month"> format) or YYYY, with ${name}Start / ${name}End under range.

<MonthPicker name="reportMonth" /> // reportMonth=2026-03
<YearPicker name="cohort" />       // cohort=2026

Anatomy

The aliases render DatePicker's own anatomy; testId lands where it does there.

PartSelectorNotes
FieldclassNames.fieldLabel, description, error.
TriggertestId → data-testidThe <button> showing the value; data-part="trigger".
Clear[data-part="clear-trigger"]Under clearable.
Popover[data-part="content"]classNames.content.
Presets railclassNames.presetsUnder presets.
Header[data-part="view-control"]Prev / next and the view switch.
Month / year cell[data-view="month"][data-value="3"], [data-view="year"][data-value="2026"]classNames.calendar.cell; data-selected, data-in-range, data-unavailable.
FooterCancel / ApplyUnder withConfirm.

On MonthCalendar / YearCalendar, testId sits on the root and cells take classNames.cell.

// No per-cell testId: Ark's own attributes already identify a month.
page.getByTestId('report-month').click();
page.locator('[data-view="month"][data-value="3"]').click();

API

MonthPicker takes every DatePicker prop except the day-only ones — minView, withTime, typeable, numOfMonths, fixedWeeks and the time-row props. YearPicker also pins maxView. MonthCalendar / YearCalendar take Calendar's props minus minView, numOfMonths, renderDay, fixedWeeks and withWeekNumbers.

Prop

Type

Accessibility

  • The trigger is a real <button> with aria-haspopup="grid" and aria-expanded, labelled by the field.
  • The month and year grids are role="grid": arrow keys move between cells (mirrored under RTL), Enter picks, Escape closes the popover and returns focus to the trigger.
  • Out-of-bounds and unavailable cells carry aria-disabled; neither a click nor Enter picks them, while the arrow keys still move past them. Selected cells carry aria-selected, and each cell's accessible name is the full month and year ("March 2026").
  • The header's prev/next buttons and view switch carry Ark's names ("Switch to previous year"), overridable through translations.

Changelog

v0.30.0
  • New MonthPicker and YearPicker, plus the inline MonthCalendar and YearCalendar, to pick a whole month or year

    #488
  • isDateUnavailable takes an optional third unit argument, and month and year cells can be unavailable; disablePast(), beforeDate, afterDate and disableDates adapt to the unit

    #488
  • New preset ids nextMonth, lastYear and nextYear, with a default preset set for month and year pickers

    #488
  • Under a month or year minView, min and max widen to the whole month or year they fall in

    #488

On this page