MonthYearField
MonthYearField renders an <input type="month"> and emits the selected value as a YYYY-MM string. Optional minMonthYear and maxMonthYear props constrain the selectable range.
Props
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| value | string | No | — | Current value in YYYY-MM format. |
| onChange | (value: string) => void | Yes | — | Called with the selected YYYY-MM string when the user changes the month. |
| label | string | No | — | Label rendered above the input. |
| description | string | No | — | Helper text rendered below the input. |
| minMonthYear | string | No | — | Minimum selectable month in YYYY-MM format. |
| maxMonthYear | string | No | — | Maximum selectable month in YYYY-MM format. |
| containerStyle | React.CSSProperties | No | — | Styles applied to the root container div. |
| inputStyle | React.CSSProperties | No | — | Styles applied directly to the <input> element. |
| labelStyle | React.CSSProperties | No | — | Styles applied to the label element. |
| descriptionStyle | React.CSSProperties | No | — | Styles applied to the description paragraph. |
| className | string | No | — | CSS class name applied to the root container. |
| id | string | No | — | id attribute on the root container. |
Usage
Basic
import React, { useState } from 'react';
import MonthYearField from '@/components/fields/MonthYearField';
export default function Example() {
const [month, setMonth] = useState('');
return (
<MonthYearField
label="Billing month"
value={month}
onChange={setMonth}
/>
);
}
With min and max constraints
<MonthYearField
label="Report period"
value={period}
onChange={setPeriod}
minMonthYear="2023-01"
maxMonthYear="2025-12"
description="Select a month between January 2023 and December 2025."
/>