Cómo funciona
Picks a time of day, 24-hour only. The trigger is the same filled field as the text input and date picker (clock button, a real input, clear button). The panel is a floating sheet with borderless columns of 36px rows and Now / OK pills; it is absolutely positioned inside the component, with no portal; it measures space once on open and flips above or aligns right if needed. Each column scrolls on its own and centers the selected item. Picks apply at once; after the hour changes, the minute moves to the nearest available one. Typed text such as 0930 or 9:30 is normalized on Enter or blur.
Úsalo para
- A time in a form: opening and closing times, booking time, scheduled publish time, shift start and end.
- Times that fit fixed steps, such as one slot every 15 minutes: set minuteStep.
- Allowed ranges or blocked periods: use min, max and disabledTime.
- Next to a date picker, one choosing the day and the other the time.
Busca otra opción cuando
- Choosing a date: use a date picker; this value has no date.
- 12-hour AM / PM time: this component is 24-hour only.
- A duration such as “remind me 30 minutes before”: use a number input with a unit or a select.
- Only three or five fixed times: a radio group or select shows them all faster.
- An ancestor with overflow: hidden and no room above or below: the panel has no portal and would be clipped.
Uso
import { useState } from 'react'
import { TimePicker } from './TimePicker.jsx'
export function PickupTimeField() {
const [time, setTime] = useState('')
return (
<div>
<label htmlFor="pickup-time">Pickup time</label>
<TimePicker
value={time}
onChange={setTime}
minuteStep={15}
min="09:00"
max="18:00"
// Closed for lunch from 12:00 to 13:00
disabledTime={(hour) => hour === 12}
name="pickupTime"
inputProps={{ id: 'pickup-time', required: true }}
/>
</div>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
value | string | — | Controlled value, 'HH:mm' ('HH:mm:ss' with showSeconds), 24-hour. An empty string means none; invalid values count as empty. |
defaultValue | string | '' | Initial value when uncontrolled. |
onChange | (value: string) => void | — | Called on a pick, a typed confirmation, “Now” or clear (empty string). Picking from the list fires at once, without waiting for OK. |
open | boolean | — | Controlled: whether the panel is open. |
defaultOpen | boolean | false | Uncontrolled: initially open. Opening initially does not take focus. |
onOpenChange | (open: boolean) => void | — | Called when the panel opens or closes. |
size | 'sm' | 'md' | 'lg' | 'md' | Trigger height 36 / 44 / 52px, radius 10 / 12 / 14px, font 14 / 15 / 16px. The panel size stays the same. |
disabled | boolean | false | Disabled: the field stays filled without its hairline, the text is muted, and it cannot open. |
invalid | boolean | false | Red hairline, a faint red fill, a red halo while focused, and aria-invalid on the input. The error text belongs to the surrounding form field. |
placeholder | string | — | Placeholder showing the format. Defaults to 'HH:mm' ('HH:mm:ss' with showSeconds). |
clearable | boolean | true | Shows a clear button when there is a value. When false, emptying the input restores the old value. |
editable | boolean | true | Whether the time can be typed. Pass false on touch screens so opening does not raise the keyboard. |
showSeconds | boolean | false | Adds a seconds column; the value becomes 'HH:mm:ss'. |
minuteStep | number | 1 | Minutes per step, commonly 5 / 10 / 15 / 30. Typed minutes off the step are rejected. |
secondStep | number | 1 | Seconds per step; matters with showSeconds. |
min | string | — | Earliest selectable time (inclusive), 'HH:mm' or 'HH:mm:ss'. |
max | string | — | Latest selectable time (inclusive), 'HH:mm' or 'HH:mm:ss'. |
disabledTime | (hour, minute, second) => boolean | — | Times returning true are faded, cannot be clicked or focused, are marked aria-disabled, and arrow keys skip them. second is always 0 when seconds are hidden. |
showNow | boolean | true | Shows a “Now” pill in the panel footer. It is grayed out when now is not selectable. |
name | string | — | Renders a hidden <input name> so native form submission carries the value, always in the standard format. |
onInvalidInput | (text, reason: 'format' | 'unavailable') => void | — | Called when typed text is not recognized (format) or is recognized but unavailable or off the step (unavailable). The old value has already been restored. |
inputProps | InputHTMLAttributes | — | Passed to the visible <input>: id (for <label htmlFor>), required, aria-label, aria-describedby and so on. |
labels | object | — | Replaces built-in text (hour, minute, second, openList, openListWithValue, clear, dialog, now, ok, hintFormat, hintMin, hintMax, hintMinuteStep, hintSecondStep, hintUnavailable). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | className, style and other attributes go to the root, which fills its container by default. Use --ds-timepicker-z to change the panel layer (default 30). |
Accesibilidad
- The input is a combobox with aria-haspopup="dialog"; the panel is a dialog, each column a named listbox, each item an option with aria-selected and aria-disabled when unavailable.
- Down opens the panel and moves focus into the hour column; Up and Down change the value, Left and Right change column, Home and End jump, Space selects, Enter confirms, Escape closes and returns focus.
- Only one item per column is in the tab order; unavailable items cannot be focused and arrow keys skip them.
- The selected item is a solid accent pill in bold text with enough contrast; unavailable items are faded, cannot be focused, and carry aria-disabled so screen readers announce them as unavailable.
- Typing errors are announced with role="alert" and say why: format, too early, off the step.
- Use <label htmlFor> with inputProps.id, and point aria-describedby at your error text when invalid.
- On touch, rows and footer pills are 44px high, and Escape closes only the panel, not an outer dialog.
Movimiento
The field's focus halo grows from 0 to 4px over 220ms. Panel enter 220ms ease-out (moves 6px and scales 0.96 to 1 from the corner touching the trigger, with a fade), exit 140ms ease-in. The newly chosen pill pops in (scale 0.8 to 1, 320ms spring); only the new pill moves and hover has no transition, so holding an arrow key leaves no trail. With reduced motion the panel only fades and nothing else moves.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
TimePicker.jsxtime-picker.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





