# MonthPicker & YearPicker (/docs/month-picker)





`MonthPicker` and `YearPicker` commit a whole month or a whole year: a reporting month, a cohort's
start year. They are [`DatePicker`](/docs/date-picker) 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`](/docs/calendar).

```tsx
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 [#playground]

<story.Playground />

## The value [#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:

<Preview code="&#x22;const [month, setMonth] = useState<Date | null>(new Date(2013, 6, 1));\nconst [period, setPeriod] = useState<DateRangeValue>({ start: null, end: null });\n\n<MonthPicker label=\&#x22;Reporting month\&#x22; value={month} onChange={setMonth} />\n<MonthPicker label=\&#x22;Period\&#x22; range value={period} onChange={setPeriod} />&#x22;">
  <MonthPickerValueExample />
</Preview>

## Month [#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.

<story.Preview variant="Default" />

## Year [#year]

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

<yearStory.Preview variant="Default" />

## Range [#range]

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

<story.Preview variant="Range" />

<yearStory.Preview variant="Range" />

```tsx
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 [#inline]

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

<Preview code="&#x22;<MonthCalendar defaultValue={new Date(2013, 6, 1)} />\n<YearCalendar defaultValue={new Date(2013, 0, 1)} />&#x22;">
  <div className="flex flex-wrap items-start gap-8">
    <MonthCalendar defaultValue="new Date(2013, 6, 1)" />

    <YearCalendar defaultValue="new Date(2013, 0, 1)" />
  </div>
</Preview>

## Restricting selection [#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.

<story.Preview variant="Bounds" />

```tsx
<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.

<story.Preview variant="Restricted" />

<yearStory.Preview variant="Restricted" />

```tsx
<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:

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

## Presets [#presets]

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

|               | Single                             | `range`                                         |
| ------------- | ---------------------------------- | ----------------------------------------------- |
| `MonthPicker` | This month, Last month, Next month | This year, Last year (as month spans), All time |
| `YearPicker`  | This year, Last year, Next year    | This year, Last year, All time                  |

<story.Preview variant="Presets" />

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.

<story.Preview variant="Quarters" />

```tsx
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 [#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`.

<story.Preview variant="Locale (fr-FR)" />

```tsx
<MonthPicker label="Mois" locale="fr-FR" placeholder="Choisir un mois" presets defaultValue={new Date(2013, 6, 1)} />
```

```tsx
<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 [#forms]

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

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

## Anatomy [#anatomy]

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

| Part              | Selector                                                                       | Notes                                                                             |
| ----------------- | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
| Field             | `classNames.field`                                                             | Label, description, error.                                                        |
| Trigger           | `testId` → `data-testid`                                                       | The `<button>` showing the value; `data-part="trigger"`.                          |
| Clear             | `[data-part="clear-trigger"]`                                                  | Under `clearable`.                                                                |
| Popover           | `[data-part="content"]`                                                        | `classNames.content`.                                                             |
| Presets rail      | `classNames.presets`                                                           | Under `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`. |
| Footer            | Cancel / Apply                                                                 | Under `withConfirm`.                                                              |

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

```ts
// 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 [#api]

`MonthPicker` takes every [`DatePicker` prop](/docs/date-picker#api) 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`.

<TypeTable
  type="{
  range: { type: 'boolean', default: 'false', description: 'Select a { start, end } range of months or years.' },
  value: { type: 'Date | null | { start, end }', description: &#x22;Controlled value: the month's (or year's) first day.&#x22; },
  defaultValue: { type: 'Date | null | { start, end }', description: 'Uncontrolled initial value. A mid-month date shows as its month.' },
  onChange: { type: '(value) => void', description: &#x22;Fires with the first day of the picked month or year, at midnight in timeZone.&#x22; },
  min: { type: 'Date', description: 'Earliest selectable month or year — the whole unit it falls in.' },
  max: { type: 'Date', description: 'Latest selectable month or year — the whole unit it falls in.' },
  isDateUnavailable: { type: '(date: Date, timeZone?: string, unit?: &#x22;day&#x22; | &#x22;month&#x22; | &#x22;year&#x22;) => boolean', description: &#x22;Asked about each cell, with its first day and the unit.&#x22; },
  maxView: { type: '&#x22;month&#x22; | &#x22;year&#x22;', default: '&#x22;year&#x22;', description: 'MonthPicker only: the highest view the header climbs to.' },
  presets: { type: 'DatePreset[] | boolean', description: 'Preset rail. true = the unit\'s default set.' },
  withConfirm: { type: 'boolean', default: 'false', description: 'Stage the pick; commit on Apply.' },
  clearable: { type: 'boolean', default: 'false', description: 'Renders a clear trigger once a value is set.' },
  locale: { type: 'string', description: 'Overrides the active locale context: month names and trigger text.' },
  timeZone: { type: 'string', description: 'The zone whose midnight the value lands on (default: IntlProvider, then the host).' },
  translations: { type: 'DatePickerTranslations', description: &#x22;Ark's accessible names, Cancel/Apply, preset labels by id.&#x22; },
  placeholder: { type: 'string', default: '&#x22;Pick a month&#x22; | &#x22;Pick a year&#x22;', description: 'Trigger text while empty.' },
  name: { type: 'string', description: 'Hidden input name; YYYY-MM or YYYY.' },
  size: { type: '&#x22;xs&#x22; | &#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;', default: '&#x22;md&#x22;', description: 'Trigger + grid density.' },
  variant: { type: '&#x22;default&#x22; | &#x22;unstyled&#x22;', default: '&#x22;default&#x22;', description: 'Trigger shell surface.' },
  classNames: { type: '{ field?, control?, content?, presets?, calendar?: { header?, table?, cell? }, footer? }', description: 'Per-part class overrides.' },
  testId: { type: 'string', description: 'data-testid on the trigger (on the root for the inline forms).' },
}"
/>

## Accessibility [#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`.
