Time picker
Help people enter or select a time from a list with a time picker and keyboard controls.
The time picker uses the Combobox JavaScript initializer:
Example
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxComponent API
Run the initializer after the markup exists:
import { comboboxInit } from '@uswds-tailwind/compat/combobox'
comboboxInit()There is no separate TimePicker initializer. The native select supplies the available times and their option values. The visible input displays each option’s label. The runtime generates the list items from the select options and copies the item template’s class and style.
Use the Combobox API for configuration, methods, callbacks, and cleanup. Time picker does not generate time intervals; author the options you need in the select.
Keyboard interactions
- Down Arrow in the input opens the list and focuses the highlighted option, or the first option when none is selected.
- Down Arrow on an option moves to the next option. It stays on the last option at the end of the list.
- Up Arrow on an option moves to the previous option. From the first option, it closes the list and returns focus to the input.
- Enter or Space on an option selects its value. Enter in the input selects an option whose label exactly matches the typed text, ignoring case. If none matches, it restores the previous selection.
- Escape closes the list and returns focus to the input.
These shortcuts require no Shift, Alt, Control, or Meta modifier. Up Arrow in the input has no custom action.
Progressive enhancement
Initialization visually hides the native select. For a no-JavaScript fallback, leave the select visible in the authored markup and hide the enhanced input, buttons, and list until your application initializes the component. This example does not implement that visibility switch.