Skip to content

    DatePicker

    A field-looking trigger that opens a Calendar in a popover, for picking one date or a range of dates in a form. It takes the same value props as Calendar.

    React

    Preview

    Props

    • mode
    • disabled
    • invalid
    • numberOfMonths
    • placeholder
    • size
    import { DatePicker } from "@/components/ui/date-picker"
    
    <DatePicker placeholder="Pick a date" />

    Usage

    When to use

    • Picking one date in a form, next to other fields, with the same field look as Input.
    • Limiting the choice to real dates, with disabled days or a min and max date.

    When not to use

    • A whole month on the page when the date is the point of the screen. Use Calendar.
    • Entering a date as text, such as a birth date the user knows by heart. Use Input.
    • Picking a time of day. Use TimePicker.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    modeYesYesYes
    valueYesYesYes
    defaultValueYesDeferredDeferredNot generated for iOS and Android.
    onValueChangeYesYesYes
    disabledYesYesYes
    invalidYesYesYes
    minDateYesYesYes
    maxDateYesYesYes
    localeYesDeferredDeferredNot generated for iOS and Android.
    weekStartsOnYesYesYes
    numberOfMonthsYesDeferredDeferredNot generated for iOS and Android.
    captionLayoutYesYesYesDeferred on iOS and Android: dropdown, dropdown-months, dropdown-years.
    value of captionLayout: dropdownYesDeferredDeferred
    value of captionLayout: dropdown-monthsYesDeferredDeferred
    value of captionLayout: dropdown-yearsYesDeferredDeferred
    rangeStartLabelYesYesYes
    rangeEndLabelYesYesYes
    placeholderYesYesYes
    sizeYesYesYes
    modalYesDeferredDeferredNot generated for iOS and Android.
    sheetTitleNoYesYesOnly on iOS, Android.
    value of keyboard: Space, EnterYesDeferredDeferred
    value of keyboard: EscapeYesDeferredDeferred

    Variants

    size

    Trigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it.

    • sm

    • mddefault

    • lg

    • xl

    import { DatePicker } from "@/components/ui/date-picker"
    
    <DatePicker size="sm" placeholder="Pick a date" />
    <DatePicker placeholder="Pick a date" />
    <DatePicker size="lg" placeholder="Pick a date" />
    <DatePicker size="xl" placeholder="Pick a date" />

    Examples

    In a form

    The trigger has the field look, and the grid opens in a popover.

    import { DatePicker } from "@/components/ui/date-picker"
    
    <DatePicker placeholder="When does it start?" />

    Booking dates

    A range over two months. The popover stays open after check-in and closes after check-out.

    import { DatePicker } from "@/components/ui/date-picker"
    
    <DatePicker mode="range" numberOfMonths={2} placeholder="Check-in to check-out" />

    Do and don't

    Do

    • Use DatePicker in forms, next to Input fields of the same size.
    • Name it with a Label pointing at its id, and describe it with aria-describedby, like any field.
    • Disable days that can never be picked, such as past days or closed days, over a minDate and maxDate.

    Don't

    • Don't use it when the date is the whole screen; put a Calendar on the page instead.
    • Don't put long text in the trigger; it shows one formatted date or one range.
    • Don't use it for dates the user knows by heart, such as a birth date; an Input is faster.

    Props

    NameTypeValuesDefaultDescription
    modeenumsingle | rangesinglesingle picks one Date; range picks a start and an end ({ from, to }) and closes once both are picked.
    valueDate | DateRange--The picked Date, or in range mode the picked range ({ from, to }), when you control it. An explicit undefined clears the selection; omitting value uses internal state. Pair it with onValueChange.
    defaultValueDate | DateRange--The Date, or in range mode the range, picked on first render, when you don't control it. Not generated for iOS and Android.
    onValueChange(value: Date | DateRange | undefined) => void--Called with the picked Date, or undefined when the user unpicks it. In range mode only with a complete range, or undefined when a one-day range is cleared.
    disabledboolean-falsetrue disables the trigger; a function receives a Date and disables single days in the Calendar, such as weekends or past dates.
    invalidboolean-falseMarks the value as wrong: sets aria-invalid, which draws the danger border.
    minDatestring--No day before this Date can be picked or navigated to.
    maxDatestring--No day after this Date can be picked or navigated to.
    localestring--A date-fns Locale object for the trigger text and the Calendar's month and weekday names. The default is enUS. Not generated for iOS and Android.
    weekStartsOnenum0 | 1-The first day of the week in the Calendar: 0 Sunday or 1 Monday. Follows the locale when not set.
    numberOfMonthsnumber-1How many months the Calendar shows, side by side from sm and stacked below it. Use two for ranges that often cross a month. Not generated for iOS and Android.
    captionLayoutenumlabel | dropdown | dropdown-months | dropdown-yearsdropdownPassed to the Calendar. dropdown is a month select and a year select. dropdown-months and dropdown-years show one select and leave the other as text. label is the month and year as text. With a year select and no minDate or maxDate, the years run from 100 years before today to 100 years after. On native v1, all captionLayout values (label, dropdown, dropdown-months, dropdown-years) render as label until v2. Deferred on iOS and Android: dropdown, dropdown-months, dropdown-years.
    rangeStartLabelstring-start of rangeRange mode. Added to the start day's accessible name in the Calendar; translate it with the locale.
    rangeEndLabelstring-end of rangeRange mode. Added to the end day's accessible name in the Calendar; translate it with the locale.
    placeholderstring-Pick a dateText shown in the trigger while no date is picked. It also names the dialog when there is no aria-label.
    sizeenumsm | md | lg | xlmdTrigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it.
    modalboolean-falseWhether the open popover blocks interaction with the rest of the page. Not generated for iOS and Android.
    sheetTitle requiredstring--The name of the Sheet that holds the Calendar. Shown as its title and read by assistive technology. Native only. Only on iOS, Android.

    Anatomy

    PartDescription
    rootThe trigger button: the same field look as Input, in the size you set.
    iconA decorative Tabler Calendar icon at the start, 16px (20px in xl), secondary.
    labelThe picked date, formatted long; in range mode both ends in the medium format joined by an en dash (one date for a one-day range); or the placeholder in secondary text.
    hitAreaTransparent ::before centered on the trigger, never smaller than size-target-min (24px on mouse, 44px on touch), so sm, md and lg stay easy to tap.
    contentThe Popover that holds a Calendar.

    Accessibility

    Role: button

    KeysAction
    Space, EnterOn the trigger, opens the popover and focuses the selected day, or today.
    EscapeCloses the popover and returns focus to the trigger. In range mode a start without an end is dropped and the value is unchanged.
    • The trigger opens a dialog named by aria-label or the placeholder; inside it, the Calendar grid keeps its own keyboard model.
    • A picked date closes the dialog and focus returns to the trigger.
    • In range mode the popover keeps a draft: it stays open after the start and sends onValueChange only with a complete range (then closes), or with undefined when the user clears a one-day range. A form value is never start-only. Closing with only a start drops it.
    • The trigger accepts id, aria-label and aria-describedby, so a Label and a hint can name and describe it like any field.

    Install

    npx werewolf-ui add date-picker

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.