Skip to content

DatePicker

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

NameTypeRequiredDefaultDescription
valueDate | nullNo

Controlled selected date (null for none). Emitted dates are always local midnight.

defaultValueDate | nullNonull

Initial date for uncontrolled usage.

onValueChange(date: Date | null) => voidNo

Called with the new date (local midnight) or null whenever the selected day changes.

formatDate(date: Date) => stringNoIntl.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 as its inverse: without it, typed text is parsed with the default parser for locale (development warning).

parseDate((text: string) => Date) | nullNo

Parses typed text into a date (null when it is not one); the result is normalized to local midnight. The default is the exact inverse of the default format for locale and also accepts ISO yyyy-mm-dd.

localestringNo

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 fa-IR, -u-ca-islamic, -u-ca-japanese) is replaced by the Gregorian one in the locale's language and digits; the Buddhist years of th-TH stay. A tag Intl rejects (the POSIX de_DE, a typo) falls back to the runtime default locale (development warning).

minDateDateNo

Earliest selectable day (the whole day is included).

maxDateDateNo

Latest selectable day (the whole day is included).

disabledDates(date: Date) => booleanNo

Returns true for days that cannot be selected (called with local-midnight dates).

placeholderstringNo'Select a date'

Placeholder text shown when no date is selected.

disabledbooleanNofalse

Whether the date picker is disabled and non-interactive (the calendar is not shown).

size'small' | 'medium' | 'large'No

Size of the field: small (24px tall), medium (32px) or large (40px). Default: the surrounding Field's size, else WaveProvider inputDefaults.size, else 'medium'. The calendar keeps its size.

positioningPopupPositioningOptionsNo`{}`: the calendar opens 4px below the field

Advanced positioning of the popup (Fluent's positioning): offset, fitViewport, matchReferenceWidth and fallbackPlacements (tried in order when the requested side has no room). The popup opens below the field.

motionMotionSlot | nullNothe 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. null turns the motion off (the surface still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. Fluent's popup surfaceMotion.

appearance'outline' | 'underline' | 'filled-darker' | 'filled-lighter'No

Look of the field: outline (a full border), underline (a bottom stroke only), filled-darker or filled-lighter (a fill without a visible stroke: give the field a visible label). Default: WaveProvider inputDefaults.appearance, else 'outline'.

readOnlybooleanNo

Makes the input read-only: the calendar does not open and the value cannot change. Turning it (or disabled) on while the user is typing drops the typed text.

clearablebooleanNofalse

Whether to show a clear button when a date is selected (not shown while readOnly). Tab from erased text clears the value before focus moves, so focus goes on to the calendar button, past the clear button that disappears with it.

firstDayOfWeek0 | 1 | 2 | 3 | 4 | 5 | 6No0

First day of the week (0 = Sunday, 1 = Monday, etc.).

todayDateNothe current date

The day marked as today in the calendar (aria-current="date") and the start of its keys when no day is selected. See Calendar's today.

initialVisibleDateDateNotoday's month

The month the calendar shows first when there is no value, clamped into minDate/maxDate.

showMonthPickerbooleanNotrue

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.

showWeekNumbersbooleanNofalse

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 'first-four-day-week' with firstDayOfWeek={1}.

showGoToTodaybooleanNofalse

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 minDate/maxDate.

showCloseButtonbooleanNofalse

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) => booleanNo

Days that draw a dot and say "marked" in their name in the calendar (labels.markedDay). Called with local-midnight dates.

renderDay(date: Date, defaultContent: React.ReactNode) => React.ReactNodeNo

Replaces the content inside a calendar day's button; defaultContent is the day number. The content must be non-interactive, and the button's name does not follow it: set the name with dayLabel.

dayLabel(date: Date, defaultLabel: string) => stringNo

The accessible name of a calendar day, from its default name (the date in words, with labels.markedDay applied for a marked day).

openbooleanNo

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.

defaultOpenbooleanNofalse

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) => voidNo

Called when the calendar opens or closes (only when the state changes).

onInvalidInput(text: string, reason: DatePickerInvalidReason) => voidNo

Called when typed text is not accepted on Enter, Alt+ArrowDown or blur (once per edit): it cannot be parsed ('unparseable'), lies outside minDate/maxDate ('out-of-range') or is excluded by disabledDates ('disabled'). The text stays in the input, which is marked aria-invalid and described by an error message (left to the surrounding Field when it shows an error). Enter reports it again when pressed again.

labelsDatePickerLabelsNo

Names of the clear, calendar and month buttons and the error texts of rejected typed text, for localization. Unset members keep their English defaults.

namestringNo

Form field name: the date is submitted as ISO yyyy-mm-dd (hidden input).

formstringNo

Id of the <form> the value belongs to, when the picker is outside it.

requiredbooleanNo

Blocks form submission while no date is selected; sets aria-required on the input. Like a native readonly input, a readOnly DatePicker does not block submission.

autoCompletestringNo'off'

Native autocomplete of the input.

onFocusReact.FocusEventHandler<HTMLInputElement>No

Focus handler of the text input (the root keeps the other handlers).

onBlurReact.FocusEventHandler<HTMLInputElement>No

Blur handler of the text input.

onKeyDownReact.KeyboardEventHandler<HTMLInputElement>No

Key handler of the text input; preventDefault() skips the picker's own keys.

onKeyUpReact.KeyboardEventHandler<HTMLInputElement>No

Key handler of the text input.

refReact.Ref<HTMLInputElement>No

Ref to the text <input>, the focusable control (Fluent UI's ref, on its primary element). The root <div> is slotProps.root.ref.

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 (preventDefault() in yours skips the DatePicker's handling of the event, its own on… prop included), your ref beside its ref, and your ids added to its aria-labelledby and aria-describedby. Every attribute the DatePicker sets on a part is locked and keeps the DatePicker's value (set it through its own props); you add the attributes it does not set. A part takes no children. The calendar's parts render while it is open; a part of a repeated element (weekday, weekNumber, day, markedDot, month, year) reaches each of them, and one ref holds the last one attached. A part of an element the DatePicker does not draw is ignored. Two exceptions to the handler rule: the calendar's tab stop always follows a focused cell after your onFocus, and a button that is disabled but stays focusable (a navigation button at a bound, an unavailable day, month or year) does not call your onClick.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • root
  • input
  • clearButton
  • openCalendarButton
  • errorMessage
  • surface
  • header
  • previousMonthButton
  • heading
  • headingButton
  • nextMonthButton
  • grid
  • weekday
  • weekNumberHeader
  • weekNumber
  • day
  • markedDot
  • month
  • year
  • footer
  • todayButton
  • closeButton

Stable class names

PartClass
rootwave-date-picker
inputwave-date-picker__input
clearButtonwave-date-picker__clear-button
openCalendarButtonwave-date-picker__open-calendar-button
errorMessagewave-date-picker__error-message
surfacewave-date-picker__surface
headerwave-date-picker__header
previousMonthButtonwave-date-picker__previous-month-button
headingwave-date-picker__heading
headingButtonwave-date-picker__heading-button
nextMonthButtonwave-date-picker__next-month-button
gridwave-date-picker__grid
weekdaywave-date-picker__weekday
weekNumberHeaderwave-date-picker__week-number-header
weekNumberwave-date-picker__week-number
daywave-date-picker__day
markedDotwave-date-picker__marked-dot
monthwave-date-picker__month
yearwave-date-picker__year
footerwave-date-picker__footer
todayButtonwave-date-picker__today-button
closeButtonwave-date-picker__close-button