Skip to content

Material 3

Components

Time picker

Time pickers help people select and set a specific time.

9:30

Select time

19
30

Time pickers let people select a time, on a dial or by typing it. Compose a TimePicker from its parts. The picker has no built-in text, apart from what the locale provides: write the text of each part yourself, in your language.

For a time typed without a dial, use the time input alone.

import {
  DialogTrigger,
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerDialog,
  TimePickerHeader,
  TimePickerInput,
  TimePickerModeToggle,
  TimePickerPeriodSelector,
} from '@material-web/react'
import { Time } from '@internationalized/date'
import { Heading } from 'react-aria-components'

Basic time picker

Write the parts of a TimePicker as its children, with their text, and name the picker with an aria-label. A picker is shown where it is written, and does not open on its own: this one is in a TimePickerDialog, as a modal time picker.

import { Time } from '@internationalized/date'
import {
  Button,
  DialogTrigger,
  Icon,
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerDialog,
  TimePickerHeader,
  TimePickerInput,
  TimePickerModeToggle,
  TimePickerPeriodSelector,
  type TimePickerDisplayMode,
  type TimePickerRenderProps,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type TimeValue } from 'react-aria-components'

const parts = ({ displayMode, selection }: TimePickerRenderProps) => (
  <>
    <TimePickerHeader>
      <Heading slot="title">{displayMode === 'picker' ? 'Select time' : 'Enter time'}</Heading>
    </TimePickerHeader>
    <TimePickerContent>
      <TimePickerInput hourLabel="Hour" minuteLabel="Minute" />
      <TimePickerPeriodSelector aria-label="Select AM or PM" />
      <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
    </TimePickerContent>
  </>
)

export default function Basic() {
  const [time, setTime] = useState<TimeValue | null>(new Time(7, 0))
  const [picked, setPicked] = useState(time)
  const [displayMode, setDisplayMode] = useState<TimePickerDisplayMode>('picker')
  return (
    <DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(time)}>
      <Button variant="outlined">
        <Icon name="schedule" />
        {time ? time.toString() : 'Pick a time'}
      </Button>
      <TimePickerDialog
        modeToggle={
          <TimePickerModeToggle
            displayMode={displayMode}
            onPress={() => setDisplayMode(displayMode === 'picker' ? 'input' : 'picker')}
            aria-label={
              displayMode === 'picker' ? 'Switch to text input mode' : 'Switch to touch input mode'
            }
          />
        }
        dismissButton={
          <Button variant="text" slot="close">
            Cancel
          </Button>
        }
        confirmButton={
          <Button variant="text" slot="close" isDisabled={!picked} onPress={() => setTime(picked)}>
            OK
          </Button>
        }
      >
        <TimePicker aria-label="Time" value={picked} onChange={setPicked} displayMode={displayMode}>
          {parts}
        </TimePicker>
      </TimePickerDialog>
    </DialogTrigger>
  )
}

A TimePicker is shown where it is written, as the controlled picker is, or in a dialog. It has two variants, the dial and the input: show both with a mode toggle between them, or the input alone.

Composition

A TimePicker is composed of these parts. It holds a TimePickerHeader and, under it, a TimePickerContent, which hold the others:

PartInUse
TimePickerHeaderTimePickerThe header
Heading with slot="title"TimePickerHeaderThe title, which names the dialog the picker is in
TimePickerContentTimePickerThe content, under the header
TimePickerInputTimePickerContentThe hour and the minute
TimePickerPeriodSelectorTimePickerContentAM and PM
TimePickerDialTimePickerContentThe dial

Leave out a part to do without it. Pass a function as the picker's children to write text that follows the display mode and the selection, such as the title. It is called with { displayMode, selection }.

const parts = ({ displayMode, selection }: TimePickerRenderProps) => (
  <>
    <TimePickerHeader>
      <Heading slot="title">{displayMode === 'picker' ? 'Select time' : 'Enter time'}</Heading>
    </TimePickerHeader>
    <TimePickerContent>
      <TimePickerInput hourLabel="Hour" minuteLabel="Minute" />
      <TimePickerPeriodSelector aria-label="Select AM or PM" />
      <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
    </TimePickerContent>
  </>
)

Set the picker's props on the TimePicker. They are those of React Aria's TimeField, except minValue, maxValue and granularity: a picker sets the hour and the minute.

To show the picker in a dialog, put it in a TimePickerDialog. Pass the dialog's buttons as confirmButton and dismissButton, and a TimePickerModeToggle as modeToggle, which the dialog places at the start of its buttons.

Hold the display mode in your own state. Pass it as displayMode to the picker and to the mode toggle, and switch it in the toggle's onPress. The toggle shows a keyboard icon in picker mode and a clock icon in input mode.

The picker reports every change through onChange. To keep the time unchanged until it is confirmed, hold the picked time in your own state and save it in the confirm button's onPress.

const [time, setTime] = useState<TimeValue | null>(new Time(7, 0))
const [picked, setPicked] = useState(time)
const [displayMode, setDisplayMode] = useState<TimePickerDisplayMode>('picker')

<DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(time)}>
  <Button variant="outlined">Pick a time</Button>
  <TimePickerDialog
    modeToggle={
      <TimePickerModeToggle
        displayMode={displayMode}
        onPress={() => setDisplayMode(displayMode === 'picker' ? 'input' : 'picker')}
        aria-label={displayMode === 'picker' ? 'Switch to text input mode' : 'Switch to touch input mode'}
      />
    }
    dismissButton={<Button variant="text" slot="close">Cancel</Button>}
    confirmButton={
      <Button variant="text" slot="close" isDisabled={!picked} onPress={() => setTime(picked)}>
        OK
      </Button>
    }
  >
    <TimePicker aria-label="Time" value={picked} onChange={setPicked} displayMode={displayMode}>
      {parts}
    </TimePicker>
  </TimePickerDialog>
</DialogTrigger>
  • As in a date picker's dialog, a button with slot="close" closes the dialog after its own onPress. Escape and a press outside the dialog close it too. Set isDismissable={false} to keep a press outside from closing it, and isKeyboardDismissDisabled to keep Escape from closing it.
  • The dialog is laid out in the locale's direction. The hour is on the left of the minute in either direction.
  • In a window too short for the picker, such as a phone in landscape with the horizontal layout, the picker scrolls inside the dialog and the buttons stay under it.

Time input

For a time that does not need a dial, show the input alone: use input mode and leave out the dial and the mode toggle.

import { Time } from '@internationalized/date'
import {
  Button,
  DialogTrigger,
  Icon,
  TimePicker,
  TimePickerContent,
  TimePickerDialog,
  TimePickerHeader,
  TimePickerInput,
  TimePickerPeriodSelector,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type TimeValue } from 'react-aria-components'

export default function InputOnly() {
  const [time, setTime] = useState<TimeValue | null>(new Time(7, 0))
  const [picked, setPicked] = useState(time)
  return (
    <DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(time)}>
      <Button variant="outlined">
        <Icon name="schedule" />
        {time ? time.toString() : 'Enter a time'}
      </Button>
      <TimePickerDialog
        dismissButton={
          <Button variant="text" slot="close">
            Cancel
          </Button>
        }
        confirmButton={
          <Button variant="text" slot="close" isDisabled={!picked} onPress={() => setTime(picked)}>
            OK
          </Button>
        }
      >
        <TimePicker aria-label="Time" value={picked} onChange={setPicked} displayMode="input">
          <TimePickerHeader>
            <Heading slot="title">Enter time</Heading>
          </TimePickerHeader>
          <TimePickerContent>
            <TimePickerInput hourLabel="Hour" minuteLabel="Minute" />
            <TimePickerPeriodSelector aria-label="Select AM or PM" />
          </TimePickerContent>
        </TimePicker>
      </TimePickerDialog>
    </DialogTrigger>
  )
}

Slots

  1. title
SlotChildUse
titleA HeadingThe picker's title. In a TimePickerDialog, it names the dialog.

Dialog

  1. close
SlotChildUse
closeAny button, such as the confirm and dismiss buttonsCloses the TimePickerDialog after its own onPress

Hour and minute

TimePickerInput shows the hour and the minute, with the locale's separator between them.

  • A press focuses the hour or the minute. The arrow keys step it, digits type it and move on to the next when it is full, and Backspace clears it.
  • Clearing the hour or the minute leaves the value as it was until the whole time is cleared. While one is cleared, a selection on the dial fills it back and keeps the other as typed. On a 12-hour clock the period is never cleared, so the value stays.
  • The hour is written with two digits, as in 07. Set shouldForceLeadingZeros={false} on the picker to write it as the locale does.

Input mode

In input mode, the hour and the minute are text inputs. Set hourLabel and minuteLabel to label them. Without a label, an input is named with the locale's name for the field. The inputs are marked as required or invalid, and described, as the picker is.

The inputs are edited as any text input, with these rules:

  • An input takes digits only, two at most: the decimal digits of any script, and the Han numerals of hanidec. A digit typed into a full input starts it over. Pasted text is taken whole.
  • Each number typed sets the time at once. A digit that would take the number past the clock's range is refused, and the text and the caret stay as they were.
  • The focus moves from the hour to the minute once the hour has two digits, or one digit from 2 to 9 on a 12-hour clock. Enter in the hour moves the focus to the minute too, and does not submit a form around the picker. Enter in the minute submits the form.
  • A cleared hour is midnight, or noon in the afternoon, and a cleared minute is zero.

A time set by the dial or the period selector is written in the inputs in the locale's digits. Switching to input mode moves the focus to the input of the selection.

Dial

TimePickerDial sets the hour or the minute, whichever is the selection:

  • A press anywhere on the dial, on a number or off it, selects the nearest hour, or the nearest five minutes.
  • A drag follows the pointer and selects the hour, or the exact minute.
  • After the pointer selects an hour, the dial moves on to the minutes. After the keyboard selects one, the dial stays on the hours.

With the keyboard, Tab moves the focus to the numbers, the arrow keys move along them, and Enter or Space selects one. Selecting the number that is already selected sets a time from the placeholder, or fills a cleared hour or minute back. Tab lands on the first number or the one last focused, not on the selected one.

Period selector

TimePickerPeriodSelector selects AM or PM, written as the locale writes them. Selecting one moves the time forward or back by twelve hours. It shows nothing on a 24-hour clock.

Selection

The selection is the part of the time that the dial sets: hour (the default) or minute. Focusing the hour or the minute selects it. Set the initial selection with defaultSelection, or control it with selection and onSelectionChange.

Controlled

Pass times as Time objects from @internationalized/date, in value, defaultValue and placeholderValue. A CalendarDateTime or a ZonedDateTime works too, and keeps its date. Set the initial time with defaultValue, or control it with value and onChange. onChange is called with the time when the dial is turned, the period is selected or a time is typed.

This picker is controlled, and so is its selection. Both are written under it.

Select time

20
00
20:00:00, hour
import { Time } from '@internationalized/date'
import {
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerHeader,
  TimePickerInput,
  type TimePickerSelection,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type TimeValue } from 'react-aria-components'

export default function Controlled() {
  const [time, setTime] = useState<TimeValue | null>(new Time(20, 0))
  const [selection, setSelection] = useState<TimePickerSelection>('hour')
  return (
    <div className="flex flex-col gap-space-200">
      <TimePicker
        aria-label="Time"
        hourCycle={24}
        value={time}
        onChange={setTime}
        selection={selection}
        onSelectionChange={setSelection}
      >
        <TimePickerHeader>
          <Heading slot="title">Select time</Heading>
        </TimePickerHeader>
        <TimePickerContent>
          <TimePickerInput />
          <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
        </TimePickerContent>
      </TimePicker>
      <span className="px-space-300 text-body-md text-on-surface-variant">
        {time ? time.toString() : 'null'}, {selection}
      </span>
    </div>
  )
}

No time

With no time, the dial shows placeholderValue, which is midnight by default, and the hour and the minute show their placeholders. The first selection on the dial takes the rest of the time from placeholderValue, keeps an hour or a minute typed meanwhile, and calls onChange with the whole time. Typing calls onChange once both the hour and the minute are typed.

import { Time } from '@internationalized/date'
import {
  Button,
  DialogTrigger,
  Icon,
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerDialog,
  TimePickerHeader,
  TimePickerInput,
  TimePickerPeriodSelector,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type TimeValue } from 'react-aria-components'

export default function Empty() {
  const [time, setTime] = useState<TimeValue | null>(null)
  const [picked, setPicked] = useState(time)
  return (
    <DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(time)}>
      <Button variant="outlined">
        <Icon name="schedule" />
        {time ? time.toString() : 'Pick a time'}
      </Button>
      <TimePickerDialog
        dismissButton={
          <Button variant="text" slot="close">
            Cancel
          </Button>
        }
        confirmButton={
          <Button variant="text" slot="close" isDisabled={!picked} onPress={() => setTime(picked)}>
            OK
          </Button>
        }
      >
        <TimePicker
          aria-label="Time"
          value={picked}
          onChange={setPicked}
          placeholderValue={new Time(12, 0)}
        >
          {({ selection }) => (
            <>
              <TimePickerHeader>
                <Heading slot="title">Select time</Heading>
              </TimePickerHeader>
              <TimePickerContent>
                <TimePickerInput />
                <TimePickerPeriodSelector aria-label="Select AM or PM" />
                <TimePickerDial
                  aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'}
                />
              </TimePickerContent>
            </>
          )}
        </TimePicker>
      </TimePickerDialog>
    </DialogTrigger>
  )
}

Display mode

The display mode is picker (the default), which shows the dial, or input, which hides the dial and shows the hour and the minute as text inputs, with hourLabel and minuteLabel under them. Set it with displayMode.

A picker does not switch its display mode itself. To let people switch it, hold it in your own state and add a TimePickerModeToggle, as in the modal time picker.

Horizontal layout

Set layout to vertical (the default) to put the dial under the time, or to horizontal to put it beside the time, as on a phone in landscape.

import { Time } from '@internationalized/date'
import {
  Button,
  DialogTrigger,
  Icon,
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerDialog,
  TimePickerHeader,
  TimePickerInput,
  TimePickerModeToggle,
  TimePickerPeriodSelector,
  type TimePickerDisplayMode,
  type TimePickerRenderProps,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type TimeValue } from 'react-aria-components'

const parts = ({ displayMode, selection }: TimePickerRenderProps) => (
  <>
    <TimePickerHeader>
      <Heading slot="title">{displayMode === 'picker' ? 'Select time' : 'Enter time'}</Heading>
    </TimePickerHeader>
    <TimePickerContent>
      <TimePickerInput hourLabel="Hour" minuteLabel="Minute" />
      <TimePickerPeriodSelector aria-label="Select AM or PM" />
      <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
    </TimePickerContent>
  </>
)

export default function Horizontal() {
  const [time, setTime] = useState<TimeValue | null>(new Time(7, 0))
  const [picked, setPicked] = useState(time)
  const [displayMode, setDisplayMode] = useState<TimePickerDisplayMode>('picker')
  return (
    <DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(time)}>
      <Button variant="outlined">
        <Icon name="schedule" />
        {time ? time.toString() : 'Pick a time'}
      </Button>
      <TimePickerDialog
        modeToggle={
          <TimePickerModeToggle
            displayMode={displayMode}
            onPress={() => setDisplayMode(displayMode === 'picker' ? 'input' : 'picker')}
            aria-label={
              displayMode === 'picker' ? 'Switch to text input mode' : 'Switch to touch input mode'
            }
          />
        }
        dismissButton={
          <Button variant="text" slot="close">
            Cancel
          </Button>
        }
        confirmButton={
          <Button variant="text" slot="close" isDisabled={!picked} onPress={() => setTime(picked)}>
            OK
          </Button>
        }
      >
        <TimePicker
          aria-label="Time"
          value={picked}
          onChange={setPicked}
          displayMode={displayMode}
          layout="horizontal"
        >
          {parts}
        </TimePicker>
      </TimePickerDialog>
    </DialogTrigger>
  )
}

Form props

Set isDisabled to disable a picker: the time, the period selector and the dial are dimmed, and cannot be pressed, typed in or focused. Set isReadOnly to keep the time as it is: the hour and the minute can be focused, but typing and the period selector change nothing, and the numbers of the dial are dimmed and cannot be selected.

Disabled

20
00

Read-only

20
00
import { Time } from '@internationalized/date'
import {
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerHeader,
  TimePickerInput,
  type TimePickerRenderProps,
} from '@material-web/react'
import { Heading } from 'react-aria-components'

const parts =
  (title: string) =>
  ({ selection }: TimePickerRenderProps) => (
    <>
      <TimePickerHeader>
        <Heading slot="title">{title}</Heading>
      </TimePickerHeader>
      <TimePickerContent>
        <TimePickerInput />
        <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
      </TimePickerContent>
    </>
  )

export default function FormProps() {
  const time = new Time(20, 0)
  return (
    <>
      <TimePicker aria-label="Disabled time" hourCycle={24} defaultValue={time} isDisabled>
        {parts('Disabled')}
      </TimePicker>
      <TimePicker aria-label="Read-only time" hourCycle={24} defaultValue={time} isReadOnly>
        {parts('Read-only')}
      </TimePicker>
    </>
  )
}
  • Form: Set name to include the picker in a form. The time is submitted as a string such as 07:30:00. See Forms.
  • Focus: Set autoFocus to focus the hour when the picker is shown.

Validation

Set isRequired to require a time, or pass a validate function for a rule of your own, as with React Aria's TimeField. A picker that fails either one blocks its form from being submitted, and is then marked as invalid. With validationBehavior set to aria, it is marked as invalid at once and the form is submitted. Set isInvalid to mark a picker as invalid yourself.

Note: An invalid picker is reported to assistive technology, and looks the same as a valid one. A picker has no minValue and no maxValue: check the time in validate.

12-hour and 24-hour clocks

The clock is the locale's, 12-hour or 24-hour. Set hourCycle to 12 or 24 to choose one yourself.

Set hourCycle={24} for a 24-hour clock, which is the default in a locale that uses one. The dial then shows the hours 0 to 11 on the outer ring and 12 to 23 on the inner ring, and a press or a drag selects from one ring or the other by its distance from the center. The period selector shows nothing.

Select time

20
00
import { Time } from '@internationalized/date'
import {
  TimePicker,
  TimePickerContent,
  TimePickerDial,
  TimePickerHeader,
  TimePickerInput,
} from '@material-web/react'
import { Heading } from 'react-aria-components'

export default function TwentyFourHour() {
  return (
    <TimePicker aria-label="Time" hourCycle={24} defaultValue={new Time(20, 0)}>
      {({ selection }) => (
        <>
          <TimePickerHeader>
            <Heading slot="title">Select time</Heading>
          </TimePickerHeader>
          <TimePickerContent>
            <TimePickerInput />
            <TimePickerDial aria-label={selection === 'hour' ? 'Select hour' : 'Select minute'} />
          </TimePickerContent>
        </>
      )}
    </TimePicker>
  )
}

Text and locale

Write the picker's text in the parts: the title, the labels under the inputs, and the aria-label of the dial, the period selector and the mode toggle. The rest follows the locale. To set a locale, wrap the picker in an I18nProvider from react-aria-components.

  • The clock is the locale's, 12 or 24 hours, unless you set hourCycle. So is the separator between the hour and the minute.
  • AM and PM are written as the locale writes them.
  • The dial's numbers are written in the locale's digits, with zero as 00, and each is named as the locale counts hours and minutes, such as 7 hours. In a locale that counts a 12-hour clock from 0, such as Japanese, the top number is 0, written 00.

Customization

Pass classes in className to restyle a picker, or one of its parts: a TimePickerHeader, a TimePickerContent, a TimePickerPeriodSelector, a TimePickerDial and a TimePickerDialog take className too. A TimePickerInput takes none. See Styling for the classes, the states and the theme.

  • Parts: Leave out a part to do without it, such as the dial and the mode toggle for a time input.
  • Mode toggle: A TimePickerModeToggle takes the props of an icon button, such as its variant.
  • Text: Write the text of each part yourself. See Text and locale.