DatePicker
A date input with a calendar dialog (APG date picker dialog).
- **Typing**: the input accepts the default display format of locale (Intl numeric year/month/day, e.g. 03/04/2025 for en-GB, 04/03/2025 for en-US) and ISO yyyy-mm-dd. Text is committed on Enter, on Alt+ArrowDown (before the calendar opens) or when the field loses focus — only when it was edited, and only when it names a different day. Text that is not an available date is kept, the input is marked invalid and an error message describes it (onInvalidInput, reported once per edit) until the text is edited or replaced (a day picked in the calendar, the clear button, a form reset, a new day from the parent).
- **Calendar**: the toggle (aria-haspopup="dialog") or Alt+ArrowDown in the input opens a modal dialog labelled by the month heading. Focus moves to the selected day (else today, else the first available day of the month) and Tab stays inside. Arrow keys move by day/week (mirrored in RTL), PageUp/PageDown by month, Shift+PageUp/PageDown by year (the day is clamped to the month), Home/End to the start/end of the week, Enter/Space select. The month text is a button (the heading button, showMonthPicker) that shows the month view, whose heading, the year, leads to the year view; Escape steps back from the year view to the month view and from there to the days, and closes only from the day view, returning focus to where the calendar was opened from (the toggle, or the input after Alt+ArrowDown); a press outside closes it too. showCloseButton adds a Close button that closes as Escape does from the day view, and showGoToToday a button that shows today's month. showWeekNumbers, markedDates, renderDay and dayLabel shape the day grid as in Calendar. Unavailable days stay focusable (aria-disabled); a day focused by pointer becomes the starting point of the arrow keys. The selected day is aria-selected on its gridcell and aria-pressed on its focusable button, so the state is announced when focus lands on it; today is aria-current="date".
- The calendar closes when the picker becomes disabled or read-only (uncontrolled open: it stays closed when the picker is enabled again), and the text typed until then is dropped.
- clearable shows a clear button while a date is selected (not while read-only). Tab from erased text clears the value first, so focus moves on to the calendar button instead of to the clear button that disappears.
- Every emitted date is local midnight. The calendar opens on the month of the selected date or today, clamped into minDate/maxDate.
- **Size and appearance**: size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the root <div>. The calendar keeps its size.
- The input receives ref, id, aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage, aria-details, tabIndex, autoFocus, onFocus/onBlur/onKeyDown/onKeyUp and the text input attributes autoComplete, autoCapitalize, autoCorrect, inputMode, spellCheck and enterKeyHint. className, style, other aria-* attributes and the remaining props stay on the root <div> (slotProps.root.ref reaches it). Inside a Field, the input is labelled and described by it.
- name/required add a hidden input for native forms (ISO yyyy-mm-dd); the value resets with its form.
- The built-in button names and error texts are English; labels localizes them.
- Pass locale explicitly when rendering on the server (see locale). The calendar renders only in the browser: an open calendar (defaultOpen, open) is closed in the server HTML and opens once the picker has hydrated.
Examples
Default
export const Default: Story = {};With Min Max
export const WithMinMax: Story = {
args: {
'aria-label': 'Delivery date',
minDate: daysFromToday(0),
maxDate: daysFromToday(30),
placeholder: 'Within 30 days',
},
};Custom Format
export const CustomFormat: Story = {
args: {
defaultValue: new Date(2025, 5, 15),
formatDate: toISO,
parseDate: (text: string) => {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text.trim());
if (!match) return null;
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
const date = new Date(year, month - 1, day);
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day
? date
: null;
},
placeholder: 'YYYY-MM-DD',
},
};Localized
export const Localized: Story = {
args: {
'aria-label': 'Datum',
locale: 'de-DE',
firstDayOfWeek: 1,
defaultValue: new Date(2025, 5, 15),
placeholder: 'TT.MM.JJJJ',
},
};Clearable
export const Clearable: Story = {
args: {
defaultValue: new Date(2025, 5, 15),
clearable: true,
},
};Disabled Dates
export const DisabledDates: Story = {
args: {
'aria-label': 'Weekday',
disabledDates: (d: Date) => d.getDay() === 0 || d.getDay() === 6,
placeholder: 'Weekdays only',
},
};Disabled
export const Disabled: Story = {
args: {
defaultValue: new Date(2025, 5, 15),
disabled: true,
},
};Invalid
export const Invalid: Story = {
args: {
'aria-label': undefined,
},
render: (args) => (
<Field label="Due date" error="Choose a date in the future." required>
<DatePicker {...args} />
</Field>
),
};Controlled
Selected: 2025-06-15
export const Controlled: Story = {
render: function ControlledDatePicker(args) {
const [value, setValue] = useState<Date | null>(new Date(2025, 5, 15));
return (
<div>
{/* The controlled pair is wired after the args on purpose. */}
<DatePicker
{...args}
value={value}
onValueChange={(date) => {
setValue(date);
args.onValueChange?.(date);
}}
/>
<p className="mt-2 text-wave-body-1">Selected: {value ? toISO(value) : '(none)'}</p>
</div>
);
},
};Month And Year Picker
This example opens a dialog or panel. Use the button to show it.
export const MonthAndYearPicker: Story = {
args: {
'aria-label': 'Birth date',
showMonthPicker: true,
defaultValue: new Date(2025, 5, 15),
today: new Date(2025, 5, 18),
defaultOpen: true,
},
parameters: openStoryParameters,
};Week Numbers
This example opens a dialog or panel. Use the button to show it.
export const WeekNumbers: Story = {
args: {
showWeekNumbers: true,
firstDayOfWeek: 1,
defaultValue: new Date(2025, 5, 15),
today: new Date(2025, 5, 18),
defaultOpen: true,
},
parameters: openStoryParameters,
};Close Button
This example opens a dialog or panel. Use the button to show it.
export const CloseButton: Story = {
args: {
showCloseButton: true,
showGoToToday: true,
defaultValue: new Date(2025, 5, 15),
today: new Date(2025, 5, 18),
defaultOpen: true,
},
parameters: openStoryParameters,
};Sizes And Appearances
export const SizesAndAppearances: Story = {
render: (args) => (
<SizeAppearanceGrid
render={(size, appearance) => (
<DatePicker
{...args}
size={size}
appearance={appearance}
clearable
defaultValue={new Date(2026, 0, 5)}
aria-label={`${size} ${appearance}`}
/>
)}
/>
),
};Motion
export const Motion: Story = {
render: function MotionPopups(args) {
return (
<div className="flex flex-wrap gap-4">
{motionCases(fadeAndZoom).map(({ label, motion }) => (
<DatePicker
key={label}
{...args}
aria-label={label}
motion={motion}
placeholder={label}
/>
))}
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value | Date | null | No | Controlled selected date ( | |
defaultValue | Date | null | No | null | Initial date for uncontrolled usage. |
onValueChange | (date: Date | null) => void | No | Called with the new date (local midnight) or | |
formatDate | (date: Date) => string | No | Intl.DateTimeFormat(locale, { year: 'numeric', month: '2-digit', day: '2-digit' }),
in the Gregorian calendar when the locale's own has other months (see `locale`) | Formats the selected date for the input. Supply |
parseDate | ((text: string) => Date) | null | No | Parses typed text into a date ( | |
locale | string | No | BCP 47 locale of the default format/parse, the month and weekday names and the day labels (runtime default when omitted). Pass it explicitly when rendering on the server, so the server and the browser format the same text. The grid is Gregorian: a locale calendar with other months or eras (the Persian default of | |
minDate | Date | No | Earliest selectable day (the whole day is included). | |
maxDate | Date | No | Latest selectable day (the whole day is included). | |
disabledDates | (date: Date) => boolean | No | Returns | |
placeholder | string | No | 'Select a date' | Placeholder text shown when no date is selected. |
disabled | boolean | No | false | Whether the date picker is disabled and non-interactive (the calendar is not shown). |
size | 'small' | 'medium' | 'large' | No | Size of the field: | |
positioning | PopupPositioningOptions | No | `{}`: the calendar opens 4px below the field | Advanced positioning of the popup (Fluent's |
motion | MotionSlot | null | No | the fade and slide above | The calendar's motion. By default it fades in and slides 4px away from the field, on the side it opened on, over 200 ms with a decelerating curve, and fades out and slides back over 100 ms with an accelerating curve (focus has moved out of it by then); under reduced motion it appears and disappears at once. |
appearance | 'outline' | 'underline' | 'filled-darker' | 'filled-lighter' | No | Look of the field: | |
readOnly | boolean | No | Makes the input read-only: the calendar does not open and the value cannot change. Turning it (or | |
clearable | boolean | No | false | Whether to show a clear button when a date is selected (not shown while |
firstDayOfWeek | 0 | 1 | 2 | 3 | 4 | 5 | 6 | No | 0 | First day of the week (0 = Sunday, 1 = Monday, etc.). |
today | Date | No | the current date | The day marked as today in the calendar ( |
initialVisibleDate | Date | No | today's month | The month the calendar shows first when there is no value, clamped into |
showMonthPicker | boolean | No | true | Turns the calendar's month text into a button that shows the month view, whose heading, the year, is a button to the year view. Escape steps back from the year view to the month view and from there to the days; it closes the calendar only from the day view. |
showWeekNumbers | boolean | No | false | Adds a leading column of week numbers to the calendar. |
firstWeekOfYear | 'first-day' | 'first-full-week' | 'first-four-day-week' | No | 'first-day' | Which week is week 1 of a year. ISO 8601 is |
showGoToToday | boolean | No | false | Adds a "Go to today" button to the calendar's footer: it shows today's month and focuses today without selecting it, and is disabled while today is outside |
showCloseButton | boolean | No | false | Adds a Close button to the calendar's footer; it closes the calendar as Escape does from the day view (focus returns to the toggle, or to the input after Alt+ArrowDown). |
markedDates | (date: Date) => boolean | No | Days that draw a dot and say "marked" in their name in the calendar ( | |
renderDay | (date: Date, defaultContent: React.ReactNode) => React.ReactNode | No | Replaces the content inside a calendar day's button; | |
dayLabel | (date: Date, defaultLabel: string) => string | No | The accessible name of a calendar day, from its default name (the date in words, with | |
open | boolean | No | Controlled open state of the calendar. The calendar renders only in the browser: an open picker is closed in the server HTML and opens once it has hydrated. | |
defaultOpen | boolean | No | false | Initial open state for uncontrolled usage. A picker that starts disabled or read-only starts closed. The calendar renders only in the browser: it is closed in the server HTML and opens once the picker has hydrated. |
onOpenChange | (open: boolean) => void | No | Called when the calendar opens or closes (only when the state changes). | |
onInvalidInput | (text: string, reason: DatePickerInvalidReason) => void | No | Called when typed text is not accepted on Enter, Alt+ArrowDown or blur (once per edit): it cannot be parsed ( | |
labels | DatePickerLabels | No | Names of the clear, calendar and month buttons and the error texts of rejected typed text, for localization. Unset members keep their English defaults. | |
name | string | No | Form field name: the date is submitted as ISO | |
form | string | No | Id of the | |
required | boolean | No | Blocks form submission while no date is selected; sets | |
autoComplete | string | No | 'off' | Native |
onFocus | React.FocusEventHandler<HTMLInputElement> | No | Focus handler of the text input (the root keeps the other handlers). | |
onBlur | React.FocusEventHandler<HTMLInputElement> | No | Blur handler of the text input. | |
onKeyDown | React.KeyboardEventHandler<HTMLInputElement> | No | Key handler of the text input; | |
onKeyUp | React.KeyboardEventHandler<HTMLInputElement> | No | Key handler of the text input. | |
ref | React.Ref<HTMLInputElement> | No | Ref to the text | |
slotProps | { root?: SlotPart<'div'>; input?: SlotPart<'input'>; clearButton?: SlotPart<'button'>; openCalendarButton?: SlotPart<'button'>; errorMessage?: SlotPart<'p'>; surface?: SlotPart<'div'>; header?: SlotPart<'div'>; previousMonthButton?: SlotPart<'button'>; heading?: SlotPart<'h2'>; headingButton?: SlotPart<'button'>; nextMonthButton?: SlotPart<'button'>; grid?: SlotPart<'table'>; weekday?: SlotPart<'th'>; weekNumberHeader?: SlotPart<'th'>; weekNumber?: SlotPart<'th'>; day?: SlotPart<'button'>; markedDot?: SlotPart<'span'>; month?: SlotPart<'button'>; year?: SlotPart<'button'>; footer?: SlotPart<'div'>; todayButton?: SlotPart<'button'>; closeButton?: SlotPart<'button'> } | No | Props for the elements the DatePicker draws, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers ( |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
rootinputclearButtonopenCalendarButtonerrorMessagesurfaceheaderpreviousMonthButtonheadingheadingButtonnextMonthButtongridweekdayweekNumberHeaderweekNumberdaymarkedDotmonthyearfootertodayButtoncloseButton
Stable class names
| Part | Class |
|---|---|
root | wave-date-picker |
input | wave-date-picker__input |
clearButton | wave-date-picker__clear-button |
openCalendarButton | wave-date-picker__open-calendar-button |
errorMessage | wave-date-picker__error-message |
surface | wave-date-picker__surface |
header | wave-date-picker__header |
previousMonthButton | wave-date-picker__previous-month-button |
heading | wave-date-picker__heading |
headingButton | wave-date-picker__heading-button |
nextMonthButton | wave-date-picker__next-month-button |
grid | wave-date-picker__grid |
weekday | wave-date-picker__weekday |
weekNumberHeader | wave-date-picker__week-number-header |
weekNumber | wave-date-picker__week-number |
day | wave-date-picker__day |
markedDot | wave-date-picker__marked-dot |
month | wave-date-picker__month |
year | wave-date-picker__year |
footer | wave-date-picker__footer |
todayButton | wave-date-picker__today-button |
closeButton | wave-date-picker__close-button |