Time picker
A TimePicker sets a time of day, with one input per unit. Its value is a Date, and only the time part counts.
Usage#
import { TimePicker } from "@clawscale/react/datetime";<TimePicker precision="second" value={time} onChange={setTime} />Examples#
Precision#
precision sets the smallest unit: minute (default), second or millisecond. Type a value, or step a unit with the up and down arrow keys.
Nightly backupLog rotationTrace span start
:
::
::.
import { TimePicker } from "@clawscale/react/datetime";
export default function TimePickerPrecision() {
return (
<div style={{ alignItems: "center", display: "grid", gap: "12px 24px", gridTemplateColumns: "auto auto" }}>
<span>Nightly backup</span>
<TimePicker precision="minute" defaultValue={new Date(2026, 8, 14, 2, 30)} />
<span>Log rotation</span>
<TimePicker precision="second" defaultValue={new Date(2026, 8, 14, 0, 0, 15)} />
<span>Trace span start</span>
<TimePicker precision="millisecond" defaultValue={new Date(2026, 8, 14, 14, 7, 32, 418)} />
</div>
);
}12-hour clock#
useAmPm shows hours from 1 to 12 and an AM and PM menu. The value is still a regular Date.
:
import { TimePicker } from "@clawscale/react/datetime";
// On-call handoff at 9:00 PM.
export default function TimePickerAmPm() {
return <TimePicker useAmPm defaultValue={new Date(2026, 8, 14, 21, 0)} />;
}Arrow buttons#
showArrowButtons adds a button above and below each unit to step it up or down.
::
import { TimePicker } from "@clawscale/react/datetime";
// Daily cost report delivery.
export default function TimePickerArrowButtons() {
return <TimePicker showArrowButtons precision="second" defaultValue={new Date(2026, 8, 14, 6, 0, 0)} />;
}Minimum and maximum time#
minTime and maxTime limit the time. Only the time of each Date counts. When maxTime is earlier than minTime, the range wraps past midnight. A time outside the range reverts to the last valid one.
:
import { TimePicker } from "@clawscale/react/datetime";
// Batch jobs may only start between 22:00 and 04:00. Only the time of each date matters.
export default function TimePickerMinMax() {
return (
<TimePicker
minTime={new Date(2026, 0, 1, 22, 0)}
maxTime={new Date(2026, 0, 1, 4, 0)}
defaultValue={new Date(2026, 8, 14, 23, 30)}
/>
);
}Interactive playground#
:
Props interface#
interface TimePickerProps extends Props@clawscale/react/datetime| Props | Description |
|---|---|
autoFocus | boolean = falseWhether to focus the first input when it opens initially. |
className | stringA space-delimited list of class names to pass along to a child element. Inherited from Props |
defaultValue | DateInitial time the TimePicker will display. This should not be set if value is set. |
disabled | boolean = falseWhether the time picker is non-interactive. |
maxTime | DateThe latest time the user can select. The year, month, and day parts of the Date object are ignored. While the maxTime will be later than the minTime in the basic case, it is also allowed to be earlier than the minTime. This is useful, for example, to express a time range that extends before and after midnight. If the maxTime and minTime are equal, then the valid time range is constrained to only that one value. |
minTime | DateThe earliest time the user can select. The year, month, and day parts of the Date object are ignored. While the minTime will be earlier than the maxTime in the basic case, it is also allowed to be later than the maxTime. This is useful, for example, to express a time range that extends before and after midnight. If the maxTime and minTime are equal, then the valid time range is constrained to only that one value. |
onBlur | (event: React.FocusEvent<HTMLInputElement>, unit: TimeUnit) => voidCallback invoked on blur event emitted by specific time unit input |
onChange | (newTime: Date) => voidCallback invoked when the user changes the time. |
onFocus | (event: React.FocusEvent<HTMLInputElement>, unit: TimeUnit) => voidCallback invoked on focus event emitted by specific time unit input |
onKeyDown | (event: React.KeyboardEvent<HTMLInputElement>, unit: TimeUnit) => voidCallback invoked on keydown event emitted by specific time unit input |
onKeyUp | (event: React.KeyboardEvent<HTMLInputElement>, unit: TimeUnit) => voidCallback invoked on keyup event emitted by specific time unit input |
precision | TimePrecision = TimePrecision.MINUTEThe precision of time the user can set. |
selectAllOnFocus | boolean = falseWhether all the text in each input should be selected on focus. |
showArrowButtons | boolean = falseWhether to show arrows buttons for changing the time. |
useAmPm | boolean = falseWhether to use a 12 hour format with an AM/PM dropdown. |
value | Date | nullThe currently set time. If this prop is provided, the component acts in a controlled manner. |