Skip to content

Picker dialog

The modal form of a date or time picker, with confirm, dismiss and mode-toggle slots.

import { PickerDialog } from '@windmorph/react';

Props

By name or description, across the 22 props below

PickerDialog 22 props

  • confirmButtontype ReactNodeRequired

    The confirm button (last, at the end), e.g. <Button variant="text">OK</Button>.

  • childrentype ReactNode | ((props: { close: () => void; }) => ReactNode)Required

    The picker.

  • opentype boolean

    Whether the dialog is open (controlled).

  • defaultOpentype booleandefault false

    Whether the dialog starts open when uncontrolled.

  • varianttype "date" | "time"default "date"

    date holds a date picker edge to edge with the actions below (Compose's DatePickerDialog); time pads the content 24px under a "Select time" style title (Compose's TimePickerDialog).

  • titletype ReactNode

    Title for the time variant, e.g. "Select time".

  • dismissButtontype ReactNode

    The dismiss button, before the confirm button.

  • modeToggleButtontype ReactNode

    A control at the start of the actions row, e.g. the time picker's mode toggle.

  • fullScreentype "never" | "always" | "compact"default "never"

    Fill the window, with a close (x) icon button and a Save button at the top instead of the actions (M3: a full-screen modal date picker is recommended on compact windows). compact does so below 600px wide.

  • closeIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon of the full-screen close button.

  • transitiontype "reveal" | "scale"default "reveal"

    How the dialog enters and leaves, as Dialog's transition: reveal, the M3 dialog motion (it slides down while its container grows, then the picker and the actions fade in), or scale, the original pop (a fade with a scale from 90%). Reduced motion keeps only the fades. Ignored while the dialog is full screen.

  • closedBytype "any" | "closerequest" | "none"default "any"

    How the user can close the dialog, as HTML's <dialog closedby>: any (Escape or a press outside), closerequest (Escape only) or none (only its actions or the app).

  • idtype string

    The dialog's id (on the panel, the dialog element).

  • reftype Ref<HTMLDivElement>

    Ref to the panel, the dialog element.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the dialog opens or closes.

  • onConfirmtype (() => void)

    Saves the picked value. With it, Enter on a day (or in a typed date) confirms and closes the dialog (the M3 date picker keyboard table), and the full-screen form gets its Save button. Called after the picker's latest value has rendered.

Text

  • labelstype Partial<PickerDialogLabels>

    Words the full-screen form shows and announces, with English defaults. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    Accessible name of the dialog when there's no visible title.

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    Id of a visible element that names the dialog.

    One of aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Built to the M3 Expressive picker dialog spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Modal date picker

    Built

    Variant · Date

  • Modal time picker

    Built

    Variant · Time

  • Full-screen modal date picker

    Built

    Configuration · Full screen

  • Close affordance and Save in full screen

    Built

    Configuration · Full screen

  • Mode toggle in the actions

    Built

    Configuration · Time

  • One dialog for both pickers

    Extension

    variant (date or time) covers what Compose splits into DatePickerDialog and TimePickerDialog.

  • children as a function

    Extension

    children may be a function of { close }, so a confirm action can apply its value and close in one place.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • PickerDialog: 39.1 kB

Differences from Compose

  • One component covers Compose's DatePickerDialog and TimePickerDialog through variant: date holds the picker edge to edge with the actions below; time pads the content 24px and shows a label-medium title.
  • The panel is surface-container-high with 28px corners at elevation 3, on the dialog's scrim and motion. Date actions sit 8px apart with 8px below and 6px from the end; the time variant puts the mode toggle at the start of the actions row.
  • Full screen follows the M3 full-screen dialog, as Dialog does: the panel fills the window on surface-container-high (the date picker's container colour) with no corners or elevation, under a 56px row holding the close button and Save; the range picker's month list fills the height.
  • In a window too short for the whole dialog, or with large text, the picker scrolls between the title and the actions, which stay in view.
  • children may be a function of { close }, so a confirm action can apply its value and close in one place.