suiss/ui ยท Pattern
Date Picker
A date field that opens a calendar popover on desktop and wheel pickers in a drawer on mobile.
Date Picker is an open-source pattern from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
DatePicker renders a field-style trigger showing the selected date or the placeholder. On desktop the trigger opens a Popover with a Calendar. Below the 48rem breakpoint it opens a bottom Drawer with a WheelPicker of day, month and year columns.
Use it for form fields such as delivery dates or dates of birth.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
-
Add the pieces it builds on: Calendar, Drawer, Popover,
use-mobile, Wheel Picker. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
With value
Set defaultValue to start with a date. The calendar opens on that month.
Locale
Set locale to format the trigger and calendar in another language, here Turkish with locale="tr-TR". It also sets the first day of the week and the wheel order.
Year range
Set fromYear and toYear to limit selection to 1940 through 2010 for a date of birth. They bound both the calendar's months and the year wheel.
With title
Set title to show a visible Delivery date title in the mobile drawer. Without it the drawer title is visually hidden.
With close button
Set showCloseButton to add an icon close button to the mobile drawer.
With close label
Set closeLabel together with showCloseButton to show a text close button labelled Done in the mobile drawer.
Disabled
Set disabled to disable the trigger so the picker cannot open.
Invalid
Set aria-invalid to mark the field invalid and apply the destructive border and ring.
Controlled
Control the value with value and onValueChange, and show the picked date below the field.
Floating
Set floating to inset the mobile drawer from the screen edges with fully rounded corners.
Accessibility
- The trigger is a
button; give it a name witharia-labelor alabellinked throughid. - On desktop the calendar is a
gridnamed by its month caption, and each day button is named with the full localized date, prefixed with today's relative name for the current day. Escapecloses the calendar and returns focus to the trigger.- On mobile each wheel column is labelled Day, Month or Year, and the drawer always has a title, visually hidden when
titleis not set.
API Reference
DatePicker
The field trigger with its desktop calendar popover and mobile wheel drawer.
| Prop | Type | Default |
|---|---|---|
value | Date | null | - |
defaultValue | Date | null | - |
onValueChange | (value: Date | null) => void | - |
placeholder | string | "Pick a date" |
locale | string | - |
fromYear | number | new Date().getFullYear() - 100 |
toYear | number | new Date().getFullYear() + 10 |
title | string | - |
disabled | boolean | - |
floating | boolean | - |
showCloseButton | boolean | false |
closeLabel | string | - |
id | string | - |
className | string | - |
aria-invalid | boolean | - |
aria-label | string | - |
aria-describedby | string | - |
Use value and onValueChange for a controlled field, or defaultValue for an uncontrolled one; the value is a Date or null. onValueChange fires when the user picks a day or turns a wheel. The open state is internal and cannot be controlled.
The trigger formats the date with Intl.DateTimeFormat in the medium date style. locale is a BCP 47 locale that drives the trigger format, calendar captions, weekday names, the first day of the week, day labels and the wheel order; it defaults to the runtime locale. On desktop, picking a day selects it and closes the popover. On mobile the wheels follow the locale's short date format, start at today's date when no value is set, and update the value immediately; the day is clamped to the length of the chosen month.
Pass id, aria-label and aria-describedby to connect the field to a label and help text; aria-label is also the hidden drawer title when title is absent. className applies to the trigger button. The trigger sets data-slot="date-picker-trigger" and data-placeholder while empty, and the popup and wheels set date-picker-content and date-picker-wheels, for styling.
Web preview
DatePicker renders a field-style DrawerTrigger with a calendar icon and the selected date formatted with Intl.DateTimeFormat in the medium date style. Pressing it opens a Drawer with three WheelPicker columns.
The column order follows the locale's short date format, falling back to month, day, year. Month names come from the locale, and the day column shrinks or grows with the chosen month and year, clamping the day when needed. When no value is set, the wheels start at today.
Installation
The CLI also adds what it builds on: Drawer, Icon, Text, Wheel Picker.
- Install the following dependencies:
-
Add the pieces it builds on: Drawer, Icon, Text, Wheel Picker.
-
Copy and paste the following code into
components/patterns/date-picker.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Drawer, Icon, Text, Wheel Picker.
-
Copy and paste the following code into
components/patterns/date-picker.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Drawer, Icon, Text, Wheel Picker.
-
Copy and paste the following code into
components/patterns/date-picker.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
With value
Starts with a preset date via defaultValue.
Starts with a preset date.
Web preview
Locale
Uses tr-TR, which reorders the wheels and translates month names.
Web preview
Year range
A date-of-birth field limited to 1940 through 2010 with fromYear and toYear.
Web preview
With title
Adds a heading to the drawer with title.
Web preview
With close button
Shows a close button in the drawer.
Web preview
With close label
Labels the close button Done with closeLabel.
Web preview
Disabled
A disabled field that cannot open the drawer.
Web preview
Invalid
Shows the error border and tint with invalid.
Web preview
Controlled
Holds the date in state and prints the selection below.
Web preview
Floating
Detaches the drawer from the screen edges.
Web preview
The React Native tab shows 1 more example.
Accessibility
- The wheels are labelled
Day,MonthandYear. - Without a
title, the drawer is labelled byaccessibilityLabelor the placeholder.
API Reference
DatePicker
| Prop | Type | Default |
|---|---|---|
value | Date | null | - |
defaultValue | Date | null | - |
onValueChange | (value: Date | null) => void | - |
placeholder | string | "Pick a date" |
locale | string | - |
fromYear | number | new Date().getFullYear() - 100 |
toYear | number | new Date().getFullYear() + 10 |
title | string | - |
disabled | boolean | - |
floating | boolean | - |
showCloseButton | boolean | false |
closeLabel | string | - |
invalid | boolean | - |
className | string | - |
accessibilityLabel | string | - |
accessibilityLabelledBy | string | - |
Use it uncontrolled with defaultValue, or controlled with value and onValueChange. The value is a Date or null; onValueChange fires on every wheel change, so there is no separate confirm step. When no value is set the field shows placeholder.
locale is a BCP 47 locale for formatting, month names and wheel order. fromYear and toYear limit the year wheel and default to 100 years ago and 10 years ahead. The field sizes itself to its content; pass a className such as w-full to fill the width. accessibilityLabel labels the field and also the drawer when there is no title, and accessibilityLabelledBy links the field to a visible label. Without floating, the drawer's top corners are square.
DatePickerField
| Parameter | Type | Default |
|---|---|---|
selection | Binding<Date?> | - |
placeholder | LocalizedStringKey | "Pick a date" |
fromYear | Int? | nil |
toYear | Int? | nil |
title | LocalizedStringKey? | nil |
showCloseButton | Bool | false |
closeLabel | LocalizedStringKey? | nil |
DatePicker
The field trigger with its desktop calendar popover and mobile wheel drawer.
| Parameter | Type | Default |
|---|---|---|
value | Date? | - |
onValueChange | (Date) -> Unit | - |
modifier | Modifier | Modifier |
placeholder | String | "Pick a date" |
locale | Locale | Locale.getDefault() |
fromYear | Int | Calendar.getInstance().get(Calendar.YEAR) - 100 |
toYear | Int | Calendar.getInstance().get(Calendar.YEAR) + 10 |
title | String? | null |
enabled | Boolean | true |
invalid | Boolean? | null |
floating | Boolean | false |
showCloseButton | Boolean | false |
closeLabel | String? | null |