CxJS

MonthPicker

import { MonthPicker } from 'cx/widgets'; Copied

The MonthPicker widget is a standalone component for selecting months or month ranges. It’s commonly used in reporting scenarios where users need to select reporting periods such as fiscal years, quarters, or custom month ranges. It’s also used internally by MonthField.

export default () => (
  <MonthPicker value={bind(m.month, "2024-06-01")} style="height: 25em" />
)
1980JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1981JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1982JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1983JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1984JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1985JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1986JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1987JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1988JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1989JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1990JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1991JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1992JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1993JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1994JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1995JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4

Range Selection

In range mode, the picker provides quick selection options:

  • Click on a year to select the entire year (Jan - Dec)
  • Click on a quarter (Q1, Q2, Q3, Q4) to select all three months in that quarter
  • Drag across months to select a custom range
<MonthPicker
  range
  from={bind(m.from, "2024-03-01")}
  to={bind(m.to, "2024-06-01")}
  style="height: 25em"
/>
1980JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1981JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1982JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1983JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1984JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1985JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1986JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1987JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1988JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1989JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1990JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1991JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1992JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1993JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1994JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4
1995JanFebMarQ1
AprMayJunQ2
JulAugSepQ3
OctNovDecQ4

Keyboard Navigation

The MonthPicker is fully keyboard accessible:

KeyAction
← →Move cursor between columns
↑ ↓Move cursor within column
Page UpPrevious year
Page DownNext year
EnterSelect focused month/quarter/year

Configuration

Core Properties

PropertyTypeDefaultDescription
valuestringnullSelected month (for single mode). Accepts Date or ISO string
rangebooleanfalseEnable range selection mode
fromstringStart of selected range (when range is true)
tostringEnd of selected range (when range is true)
inclusiveTobooleanfalseWhether the to date is included in the range
refDatestringReference date for initial scroll position
disabledbooleanfalseDisables the picker

Date Constraints

PropertyTypeDefaultDescription
minValuestringMinimum selectable month
minExclusivebooleanfalseIf true, the minimum month itself is not selectable
maxValuestringMaximum selectable month
maxExclusivebooleanfalseIf true, the maximum month itself is not selectable

Appearance

PropertyTypeDefaultDescription
startYearnumber1980First year shown in the picker
endYearnumber2030Last year shown in the picker
bufferSizenumber15Number of years rendered at once
hideQuartersbooleanfalseHide the quarter selection column

Validation

PropertyTypeDefaultDescription
minValueErrorTextstring"Select {0:d} or later."Error message when value is before minimum
minExclusiveErrorTextstring"Select a date after {0:d}."Error message when value equals exclusive minimum
maxValueErrorTextstring"Select {0:d} or before."Error message when value is after maximum
maxExclusiveErrorTextstring"Select a date before {0:d}."Error message when value equals exclusive maximum

Callbacks

PropertyTypeDescription
onSelectfunction(instance, dateFrom, dateTo) => void - Called when selection is made
onBeforeSelectfunction(e, instance, dateFrom, dateTo) => boolean - Return false to prevent selection
onBlurfunction(e, instance) => void - Called when picker loses focus
onFocusOutfunction(e, instance) => void - Called when focus leaves the picker