Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

TimeField

A time of day in a form: typed loosely, or with picker chosen from columns that roll under a lens, and reported as 24-hour HH:MM.

Arrows step the part under the caret

When to useLink to "When to use"

  • A time of day in a form or filter: an opening hour, a reminder, a schedule.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { TimeField } from "@arshad-shah/cynosure";

<TimeField label="Start time" value={start} onChange={setStart} min="09:00" max="17:30" step={15} picker />

The value is HH:MM (or HH:MM:SS with seconds) or null. 930, 9:30 pm and 12am are understood; anything that is not a time is kept for correcting and explained.

Explains what it cannot take

The pickerLink to "The picker"

picker adds a clock button at the end of the field. It opens columns for hours and minutes; the chosen time sits in the lens and applies at once.

Pick from the columns

12-hour and 24-hourLink to "12-hour and 24-hour"

By default the field follows the person's own language and region: 9:30 PM where AM and PM are used, 21:30 elsewhere. locale names the region for them; hourCycle={12} or hourCycle={24} fixes the form for everyone. The value, min, max and what a form receives stay 24-hour.

Follows the persons locale

With 12-hour display the picker gains an AM/PM switch.

Twelve hour

Limits and the day trackLink to "Limits and the day track"

The strip under the columns is the whole day: click or drag to jump to a time. The hours outside min and max are hatched, and their rows are struck through.

The day track

Without the day track, with secondsLink to "Without the day track, with seconds"

dayTrack={false} keeps the columns without the strip; seconds adds a third column.

Without the day track and with seconds

PropsLink to "Props"

Every prop of TimeField
PropWhat it doesTypeDefault
labelRequired
The field's visible label, and its accessible name.ReactNode
labelHidden
Hide the label visually; it still names the field.boolean
description
Help text under the field, read with it by screen readers.ReactNode
error
Your own error; it replaces the field's own messages.ReactNode
value
HH:MM (or HH:MM:SS with seconds), 24-hour whatever hourCycle shows, or null when empty.string | null
defaultValue
The starting time when value is not given, in the same form.string | null
onChange
A valid time (or null when cleared), when typing is finished, the arrows step it or the picker chooses it.((time: string | null) => void)
min
The earliest time allowed, in the same form. Earlier times are explained and not reported.string
max
The latest time allowed, in the same form. Later times are explained and not reported.string
step
Minutes between the picker's minutes, and what the arrows move the minutes by. Default 1 (Shift: ten steps).number1 (Shift: ten steps)
seconds
Include seconds.boolean
hourCycle
How the time is shown: 24 as 21:30, 12 as 9:30 PM (with an AM/PM switch in the picker), or "auto" to follow the person's own language and region. The value is 24-hour either way. Default "auto"."auto" | 12 | 24"auto"
locale
The language and region hourCycle="auto" follows, such as en-GB. Default: the browser's.stringthe browser's
picker
Add a clock button that opens a picker: columns for hours and minutes that roll under one lens. Without it the field is only typed in.boolean
dayTrack
With picker: the strip of the whole day under the columns, to click or drag to a time. Default true.boolean`true`
name
Form field name. The form receives the 24-hour HH:MM value (never the text being typed), however it is shown.string
form
The id of a form elsewhere on the page that the field belongs to.string
required
The form cannot be submitted while the field is empty.boolean
disabled
Cannot be focused, changed or submitted.boolean
readOnly
Shown and submitted but not changed: no typing, no arrows and no picker button.boolean
size
Height and text size of the field. Default "md".Size"md"
labels
Replace the built-in English text: the two messages and the picker's names.Partial<TimeFieldLabels>
className
Added to the root element, for layout.string
style
Layout only.CSSProperties
layout
stack puts the label above the control and the description and error below it. split puts the label and description at the start and the control at the end of one row (a settings row); when the field is too narrow for both, the control moves under the text. Default "stack"."stack" | "split""stack"
width
Width of the control, so the controls of a column of fields line up: "sm", "md" and "lg" are the --cy-field-control-width-* tokens (never wider than the field), "full" is the whole field. Default: the control's own width (the whole field in the stacked layout for TextField and the other fields).FieldWidth

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

In the field:

Behaviour and accessibility, table 1
KeyDoes
EnterFinish typing
Up / DownStep the part the caret is in: hours, minutes (by step, onto its grid), seconds, or AM/PM; Shift: ten times as far

In the picker (with picker):

Behaviour and accessibility, table 2
KeyDoes
Up / DownRoll the focused column to the next allowed row; the time changes at once
Home / EndFirst and last allowed row
Left / RightThe column before or after
DigitsSeek in the column: 1 then 4 is 14
A / PMorning or afternoon, when the time is shown as 12-hour
EnterClose the picker and return to the field
EscapeClose the picker
Arrows, Page Up / Down on the day trackMove by step, or by an hour
  • Errors are the field's description and set aria-invalid.
  • Limits: min and max stop the arrows and the day track; typed times outside them are explained; their rows in the picker are disabled.
  • The picker is a dialog named by labels.open. Each column is a listbox named by labels.hours, labels.minutes or labels.seconds; the day track is a slider that reads out the time.
  • Scrolling a column chooses the row it stops on. With reduced motion the columns jump instead of gliding.
  • Right to left: hours, minutes and seconds keep their order.

TouchLink to "Touch"

The field asks for the numeric keyboard (the full one when the time is shown as 12-hour, to type AM and PM). In the picker, rows are at least 44px tall on coarse pointers and a column is rolled with a finger.

ThemingLink to "Theming"

The field follows TextField, the popup Popover, the day track Slider and the AM/PM switch SegmentedControl. The picker's own tokens:

Theming, table 3
TokenDoes
--cy-time-field-row-heightHeight of a row in the columns (never below the touch hit area)
--cy-time-field-column-widthWidth of one column
--cy-time-field-lens-backgroundBackground of the band the chosen time sits in
--cy-time-field-nightColour of the day track at midnight
--cy-time-field-dayColour of the day track at midday

DateField · Calendar · NumberField

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog