Date and time picker
Picks a date, a time, or both from a popover with a calendar and time fields, with optional typing in the field.
Select the field to open the calendar. Choose a day, set the time and select Salvar.
When to use
- To choose a date with a time, such as a hearing or a deadline with an hour.
- To choose only a time (
mode="time"). - To choose a date that people may also type, with
editable.
When not to use
- A date only, in a compact filter or toolbar. Use the simple date picker.
- A period with a start and an end. Use the date range picker.
- Showing a calendar on the page, without a field. Use the calendar.
Examples
Date only
granularity="day" hides the time fields. closeOnSelect closes the popover
after a day is chosen.
Time only
Typing a date
With editable the field accepts dd/MM/yyyy and applies a mask. Typing a
date that is disabled shows an error under the field.
Weekdays only
disableWeekends disables Saturday and Sunday. Combine it with
calendarProps.disabled for other restrictions, such as holidays.
Two months
view="double" shows two months side by side, which helps when the next date is
usually in the following month.
Title and close button
States
Disabled
Read only
The value looks normal, but the field never opens.
Content
- Name the field by the event: “Data da audiência”, “Prazo de contestação”.
- The default placeholder is “Selecione uma data” and the editable one is
“dd/mm/aaaa”. Pass
placeholderfor a more specific hint. - Pass
localefor the calendar. It defaults to pt-BR, as do alllabels. Passlabelsto translate every string. - Always pass
defaultMonthor avaluewhen the output must be predictable. Without them the calendar opens on the current month.
Accessibility
- The trigger is a button that opens a Radix Popover. Focus is not moved into the popover on open, so the user keeps typing or tabbing from the field. Focus leaving both the field and the popover closes it.
- The popover opens on focus as well as on click.
- The calendar is
react-day-picker: arrow keys move between days,PageUpandPageDownchange month,EnterorSpaceselect. Disabled days cannot be selected. - The month and year selects, the previous and next buttons and the close button
have
aria-labels that come fromlabels. The hour, minute and second inputs also have names, andArrowLeftandArrowRightmove between them. - In
editablemode the input hasaria-label(the placeholder) unless you passidwith an external<label>. Errors are linked witharia-describedby, and the field setsaria-invalid.Entercloses the popover. - Pass
aria-describedbyandaria-invalidfrom your form to link help text and errors.
Code
import { DateTimePicker } from "@repo/ui/date-picker";
const [date, setDate] = useState<Date | undefined>();
<DateTimePicker
granularity="minute"
onChange={setDate}
placeholder="Selecione a data da audiência"
value={date}
/>;
Props
DateTimePicker| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Blocks opening the calendar and typing |
disableWeekends | boolean | false | Disables Saturday and Sunday in the calendar |
editable | boolean | false | Lets people type the date in the field (dd/MM/yyyy) |
granularity | "day" | "hour" | "minute" | "second" | second | Smallest unit shown in the time controls |
hourCycle | "12" | "24" | 24 | Shows the time in 24 hours or 12 hours with AM/PM |
mode | "date-time" | "time" | date-time | Calendar and time (default) or time only |
placeholder | string | "Selecione uma data" | Text shown when no date is selected |
readOnly | boolean | false | Shows the value but never opens the calendar |
view | "single" | "double" | single | One month or two months side by side |
More props| Prop | Type | Default | Description |
|---|---|---|---|
value | Date | — | Selected date and time. Controlled by the caller. |
onChange | (date: Date | undefined) => void | — | Called when the date or the time changes, or when the user clears it. |
defaultMonth | Date | — | Month shown when there is no value. It does not select a date. |
locale | Locale | ptBR | date-fns locale for the calendar and the displayed date. |
displayFormat | { hour24?: string; hour12?: string } | — | date-fns format of the displayed value. |
yearRange | number | 50 | Years offered before and after the current year in the year select. |
closeOnSelect | boolean | false | Closes the popover after a day is chosen. |
align | "start" | "center" | "end" | "end" | Alignment of the popover to the trigger. |
title / titleLabel | boolean / string | false / "Título" | Shows a heading at the top of the popover. Pass titleLabel translated. |
dismissable | boolean | false | Shows a close button at the top of the popover. |
calendarProps | { disabled, components, classNames } | — | Restrictions and customization of the calendar. |
container | HTMLElement | null | — | Portal target of the popover. Use it inside themed wrappers. |
labels | object | — | Every user-visible string: placeholder, clearButton, saveButton, closeButton, prevMonth, nextMonth, monthSelect, yearSelect, hour, minute, second, unavailableDate. |
weekStartsOn, showWeekNumber, showOutsideDays | Calendar props | — | Passed to the calendar. |
id, triggerId, aria-describedby, aria-invalid | string / AriaAttributes | — | Attributes for forms. `triggerId` goes to the button, `id` to the input when editable. |
Known issues
| Issue | Effect |
|---|---|
| The popover opens when the trigger receives focus. | Tabbing through a form opens the calendar on every date field, and it covers the next fields. |
Disabled editable fields use opacity-50, and hover uses hover:bg-neutral-black/5. |
Translucent fills and opacity lower contrast and ignore the solid-background rule. |
The popover has a hardcoded rgba(0,0,0,0.15) shadow and a hsl(var(--stroke-tertiary)) border. |
The colors do not come from the shared tokens, so a theme change does not reach them. |
titleLabel defaults to “Título” and the weekend error message “Por favor, informe um dia útil” is hardcoded. |
Apps cannot translate the weekend message, and the default title is generic. |
Without value and defaultMonth, the calendar opens on new Date(). |
The first month depends on the clock, which makes screenshots and tests unstable. |
The calendar days (day_button) define hover but no focus-visible style. |
Keyboard users rely on the browser default outline to see the focused day. |
Today uses bg-black/5 and the selected day border-white/15 and text-neutral-black. |
Translucent fills and fixed colors do not adapt to Dark and Darker themes. |