Skip to content

TimePicker

TimePicker

A time input with a filterable list of times (APG editable combobox with list autocomplete).

- Type to filter (by label or HH:mm value). A complete typed time (2:00 PM, 14:00) makes its own option active — not an earlier one that merely contains the text, such as 12:00 PM — and partial text makes the first option that starts with it active (2:00 p -> 2:00 PM), else the first one that contains it; Enter commits the active option. Enter or leaving the field also commits a complete typed time that is not in the list (9:15 AM, 14:45) when it lies within minTime/maxTime, and erased text clears the value (as the clear button does); Enter never submits the form with edited text, and both close the list. Other typed text is kept: the input is marked invalid and an error message describes it (onInvalidInput, reported once per edit) until the text is edited or replaced (an option, the clear button, Escape, a form reset, a new value from the parent). Escape on a closed list reverts any edit, erased text included, to the selected time.
- Click the input or the expand button at its end (a chevron, see expandIcon; not a tab stop, and it leaves focus in the input), press ArrowDown/ArrowUp or type to open; the list opens with every option and the selected one (when it is in the list) active and scrolled into view. Without one, no option is active until ArrowDown/ArrowUp or typing, so Enter lets the surrounding form submit. Escape, Tab, an outside press or focus leaving closes it. Typed text kept after Escape closed the list still filters it when it reopens: a click resumes the option typing made active, ArrowDown/ArrowUp start at the first/last match.
- open/defaultOpen/onOpenChange control the list. It closes when the picker becomes disabled or read-only (uncontrolled open: it stays closed when the picker is enabled again), and the text typed until then is dropped.
- Keys of an IME composition (its confirming Enter included) are left to the IME.
- clearable shows a clear button while a time is selected (not while read-only), a tab stop after the input. Tab from erased text clears the value first, so focus moves on past the picker instead of to the clear button that disappears.
- The value is HH:mm (24-hour) whatever the display format; values off the step grid or outside the bounds are still displayed in format. Without format the times follow the hour cycle of the browser's language; the server HTML and the hydration render show 12-hour times, so a server-rendered app passes format for the same output on the server.
- showSeconds adds seconds (the value becomes HH:mm:ss); formatTime and parseTime replace how times are written and read; freeform={false} limits the selection to the listed times (a complete typed time that is not listed is 'not-listed').
- **Size and appearance**: size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the root <div>. The time list keeps its size.
- The input receives ref, id, aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage, aria-details, tabIndex, autoFocus, onFocus/onBlur/onKeyDown/onKeyUp and the text input attributes autoComplete, autoCapitalize, autoCorrect, maxLength, inputMode, spellCheck and enterKeyHint. className, style, other aria-* attributes and the remaining props stay on the root <div> (slotProps.root.ref reaches it). Inside a Field, the input is labelled and described by it.
- name/required add a hidden input for native forms (HH:mm); the value resets with its form.
- The built-in names, status texts and error messages are English; labels localizes them.
- The open list renders only in the browser: an open list (defaultOpen, open) is closed in the server HTML and opens once the picker has hydrated.

Examples

Default

export const Default: Story = {};

Format 12 H

export const Format12h: Story = {
  args: {
    format: '12h',
  },
};

Format 24 H

export const Format24h: Story = {
  args: {
    format: '24h',
  },
};

Custom Step

export const CustomStep: Story = {
  args: {
    step: 15,
    placeholder: 'Every 15 minutes',
  },
};

With Min Max

export const WithMinMax: Story = {
  args: {
    'aria-label': 'Meeting time',
    minTime: '09:00',
    maxTime: '17:00',
    step: 30,
    placeholder: 'Business hours',
  },
};

Validation Feedback

export const ValidationFeedback: Story = {
  args: {
    'aria-label': 'Meeting time',
    minTime: '09:00',
    maxTime: '17:00',
    placeholder: 'Business hours',
    onInvalidInput: fn(),
  },
};

Clearable

export const Clearable: Story = {
  args: {
    defaultValue: '14:00',
    clearable: true,
  },
};

Disabled

export const Disabled: Story = {
  args: {
    defaultValue: '14:00',
    disabled: true,
  },
};

Invalid

export const Invalid: Story = {
  args: {
    'aria-label': undefined,
  },
  render: (args) => (
    <Field label="Start time" error="Choose a time within opening hours." required>
      <TimePicker {...args} />
    </Field>
  ),
};

Controlled

Selected: 10:30

export const Controlled: Story = {
  render: function ControlledTimePicker(args) {
    const [value, setValue] = useState('10:30');
    return (
      <div>
        {/* The controlled pair is wired after the args on purpose. */}
        <TimePicker
          {...args}
          value={value}
          onValueChange={(next) => {
            setValue(next);
            args.onValueChange?.(next);
          }}
        />
        <p className="mt-2 text-wave-body-1">Selected: {value || '(none)'}</p>
      </div>
    );
  },
};

Sizes And Appearances

export const SizesAndAppearances: Story = {
  render: (args) => (
    <SizeAppearanceGrid
      render={(size, appearance) => (
        <TimePicker
          {...args}
          size={size}
          appearance={appearance}
          clearable
          defaultValue="09:30"
          aria-label={`${size} ${appearance}`}
        />
      )}
    />
  ),
};

Seconds

export const Seconds: Story = {
  args: { showSeconds: true, format: '24h', defaultValue: '09:30:15' },
};

Custom Format

export const CustomFormat: Story = {
  args: {
    formatTime: formatHours,
    parseTime: parseHours,
    minTime: '08:00',
    maxTime: '12:00',
    defaultValue: '09:30',
  },
};

Listed Times Only

export const ListedTimesOnly: Story = {
  args: { freeform: false, format: '24h', onInvalidInput: fn() },
};

Motion

export const Motion: Story = {
  render: function MotionPopups(args) {
    return (
      <div className="flex flex-wrap gap-4">
        {motionCases(fadeAndZoom).map(({ label, motion }) => (
          <TimePicker
            key={label}
            {...args}
            aria-label={label}
            motion={motion}
            placeholder={label}
          />
        ))}
      </div>
    );
  },
};

Windowed

export const Windowed: Story = {
  args: { step: 1, format: '24h' },
  render: (args) => <WindowedTimes {...args} />,
};

Props

NameTypeRequiredDefaultDescription
valuestringNo

Controlled selected time in HH:mm (24-hour) format; '' for no time.

defaultValuestringNo''

Initial time for uncontrolled usage (HH:mm).

onValueChange(value: string) => voidNo

Called with the new HH:mm value ('' when cleared) whenever the selected time changes.

format'12h' | '24h'Nothe hour cycle of the browser's language (`'12h'` on the server and while hydrating)

Time display format of the input and the options: '12h' (1:30 PM) or '24h' (13:30). Without it, the times follow the hour cycle of the browser's language (navigator.language: 12-hour in en-US, 24-hour in en-GB and many other locales). The server HTML and the hydration render show 12-hour times, so hydration matches, and the picker switches to the language's cycle right after; a picker mounted in the browser follows it from its first render. Pass format for the same output on the server and in the browser (Fluent's hourCycle).

showSecondsbooleanNofalse

Shows and accepts seconds (Fluent UI's showSeconds): the value is HH:mm:ss, the input and the options read 1:30:00 PM or 13:30:00, and typed seconds are kept (2:00:15 PM). The options stay step minutes apart, on whole minutes. A controlled value of HH:mm still selects its option and is reported back as HH:mm:ss when the user picks another. Without it a time's seconds are dropped.

formatTime(value: string) => stringNothe text of `format`

Text of a time, for the options and the input (Fluent UI's formatDateToTimeString, taking the time as the picker's HH:mm or, with showSeconds, HH:mm:ss value rather than a Date). It replaces format's text, so the typed text is read by parseTime (the default reader understands 13:30 and 1:30 PM, which your format may not look like). An inline function makes the options again on every render: keep its identity (a constant, or useCallback). With it the message for text that is not a time (labels.invalidTime) is given an example of the format, formatTime('13:45'), in place of the pattern.

parseTime((text: string) => string) | nullNothe reader of `13:30`, `13:30:15` and `1:30 PM`

Reads typed text into a time (Fluent UI's validateFreeFormTime, answering with the value rather than an error type): return the HH:mm (or HH:mm:ss, h:mm AM) time the text stands for, or null for text that is not a time, which is kept and reported as 'unparseable'. The time is still checked against minTime/maxTime (and the list, with freeform={false}). Typing also filters the list by the options' labels and values. Pass it with formatTime for a format the default reader does not know (13h30).

freeformbooleanNotrue

Whether a complete typed time that is not in the list can be selected (Fluent UI's freeform, which defaults to false there). With false only the listed times can be: a complete typed time that is not listed is kept and reported as 'not-listed' (a time outside minTime/maxTime is still 'out-of-range'); picking an option, Enter on the option typing made active and erasing the text work as before.

stepnumberNo30

Minutes between options. A non-finite or non-positive value falls back to 30 (development warning); fractions are floored.

minTimestringNo'00:00'

Earliest time (inclusive): HH:mm, HH:mm:ss or h:mm AM.

maxTimestringNo'23:59'

Latest time (inclusive): HH:mm, HH:mm:ss or h:mm AM. Invalid or reversed bounds give no options (development warning, "No times available", see labels).

placeholderstringNo'Select a time'

Placeholder text shown when no time is selected.

disabledbooleanNofalse

Whether the time picker is disabled and non-interactive.

size'small' | 'medium' | 'large'No

Size of the field: small (24px tall), medium (32px) or large (40px). Default: the surrounding Field's size, else WaveProvider inputDefaults.size, else 'medium'. The time list keeps its size.

positioningPopupPositioningOptionsNo`{ matchReferenceWidth: true, fitViewport: true }`

Advanced positioning of the popup (Fluent's positioning): offset, fitViewport, matchReferenceWidth and fallbackPlacements (tried in order when the requested side has no room). The popup opens below the field.

motionMotionSlot | nullNothe fade and slide above

The popup surface's motion. By default it fades in and slides 4px away from the field, on the side it opened on, over 200 ms with a decelerating curve, and fades out and slides back over 100 ms with an accelerating curve (the time list stays in the surface while it exits); under reduced motion it appears and disappears at once. The list does not fade out when its options changed as it closed (a filter reset by the selection), nor does the status row. null turns the motion off (the surface still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. Fluent's popup surfaceMotion.

appearance'outline' | 'underline' | 'filled-darker' | 'filled-lighter'No

Look of the field: outline (a full border), underline (a bottom stroke only), filled-darker or filled-lighter (a fill without a visible stroke: give the field a visible label). Default: WaveProvider inputDefaults.appearance, else 'outline'.

readOnlybooleanNo

Makes the input read-only: the list does not open and the value cannot change. Turning it (or disabled) on while the user is typing drops the typed text.

clearablebooleanNofalse

Whether to show a clear button when a time is selected (not shown while readOnly; shown disabled while disabled). It is a tab stop after the input. Tab from erased text clears the value before focus moves, so focus goes on past the clear button that disappears with it.

expandIconSlot<'span'>No

The glyph of the expand button at the end of the input (default: a chevron). The button opens and closes the list without moving focus out of the input and is not a tab stop (Alt+ArrowDown opens the list from the keyboard). null or undefined keep the chevron; false, or a value that renders nothing, hides the button. Decorative content rendered inside the built-in button: a <button> or Button passed here is not nested (its children become the glyph, with a development warning).

virtualWindowVirtualWindowNo

Renders only the options in view of a long list of times (a step of one minute makes 1,440), plus an overscan, and spacers (aria-hidden, data-virtual-spacer) as tall as the options they stand for: pass the result of useVirtualWindow({ itemSize }), or an object of your own that implements VirtualWindow. The open list is the window's scroller (it scrolls within its own maximum height, 15rem), has no block padding while windowed, and no scroll anchoring of the browser; every option is exactly itemSize tall (the default option with one line of text is 32 pixels tall). The window counts the listed options: typing narrows it, as it narrows aria-setsize. The keys move over all of them, the active option stays rendered while it is scrolled away, and opening the list scrolls the active option, else the selected one, to the middle. A closed list renders no option. The server renders no list.

openbooleanNo

Controlled open state of the list (never shown while disabled or readOnly). The list renders only in the browser: an open picker is closed in the server HTML and opens once it has hydrated.

defaultOpenbooleanNofalse

Initial open state of the list for uncontrolled usage. A picker that starts disabled or read-only starts closed. The list renders only in the browser: it is closed in the server HTML and opens once the picker has hydrated.

onOpenChange(open: boolean) => voidNo

Called when the list opens or closes (only when the state changes).

onInvalidInput(text: string, reason: TimePickerInvalidReason) => voidNo

Called when edited text is not accepted on Enter or blur (once per edit): it is not a time ('unparseable') or lies outside minTime/maxTime ('out-of-range'). The text stays in the input, which is marked aria-invalid and described by an error message (left to the surrounding Field when it shows an error); Enter and leaving the input also close the list, so it does not cover the message. Enter reports it again when pressed again.

labelsTimePickerLabelsNo

Names of the clear and expand buttons and of the list, the status texts of an empty list and the error messages of rejected text, for localization. Unset members keep their English defaults.

namestringNo

Form field name: the HH:mm value is submitted under it (hidden input).

formstringNo

Id of the <form> the value belongs to, when the picker is outside it.

requiredbooleanNo

Blocks form submission while no time is selected; sets aria-required on the input. Like a native readonly input, a readOnly TimePicker does not block submission.

autoCompletestringNo'off'

Native autocomplete of the input.

maxLengthnumberNo

Native maxlength of the input.

onFocusReact.FocusEventHandler<HTMLInputElement>No

Focus handler of the text input (the root keeps the other handlers).

onBlurReact.FocusEventHandler<HTMLInputElement>No

Blur handler of the text input.

onKeyDownReact.KeyboardEventHandler<HTMLInputElement>No

Key handler of the text input; preventDefault() skips the picker's own keys.

onKeyUpReact.KeyboardEventHandler<HTMLInputElement>No

Key handler of the text input.

refReact.Ref<HTMLInputElement>No

Ref to the text input, the role="combobox" element and the focusable control (Fluent UI's ref, on its primary element). The root <div> is slotProps.root.ref.

slotProps{ root?: SlotPart<'div'>; input?: SlotPart<'input'>; clearButton?: SlotPart<'button'>; expandButton?: SlotPart<'button'>; errorMessage?: SlotPart<'p'>; listbox?: SlotPart<'ul'>; option?: SlotPart<'li'>; checkIcon?: SlotPart<'span'>; surface?: SlotPart<'div'>; emptyMessage?: SlotPart<'div'> }No

Props for the elements the TimePicker draws, by part, merged into each part's own (Fluent UI's root, input, clearIcon, expandIcon and listbox slot props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers (preventDefault() in yours skips the TimePicker's handling of the event, its own on… prop included), your ref beside its ref, and your ids added to its aria-labelledby and aria-describedby. Every attribute the TimePicker sets on a part is locked and keeps the TimePicker's value (set it through its own props); you add the attributes it does not set. A part takes no children.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • root
  • input
  • clearButton
  • expandButton
  • errorMessage
  • listbox
  • option
  • checkIcon
  • surface
  • emptyMessage

Stable class names

PartClass
rootwave-time-picker
inputwave-time-picker__input
clearButtonwave-time-picker__clear-button
expandButtonwave-time-picker__expand-button
expandIconwave-time-picker__expand-icon
errorMessagewave-time-picker__error-message
listboxwave-time-picker__listbox
optionwave-time-picker__option
checkIconwave-time-picker__check-icon
surfacewave-time-picker__surface
emptyMessagewave-time-picker__empty-message
spacerwave-time-picker__spacer