Skip to the content
human-kit design
21 — Pickers

Clock

A time on wheels, out of a field: hours, minutes and the day period, scrolled or stepped with the arrows.

Appointment
09
30

Installation

pnpm dlx @human-kit/design add clock
npx @human-kit/design add clock
yarn dlx @human-kit/design add clock
bunx @human-kit/design add clock

The command copies the files to src/lib/components/ui/clock. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Clock from '$lib/components/ui/clock';

	let time = $state<string | null>('09:30');
</script>

<Clock.Root label="Appointment" bind:value={time} />

Examples

Steps and limits

minuteStep keeps only the minutes the schedule books, and minValue and maxValue turn off the times outside opening hours. A time outside them stays on the wheel, greyed out, so the wheel keeps its order.

Consultation
10
00

Guidelines

  • Use Clock.Root when picking the time is the whole task: on its own in a panel, or beside a calendar. In a row of form fields, use the time picker, which opens these same wheels from a field.
  • Use the outline variant when the clock stands on the page, filled for one that should read lighter than a card, and ghost inside a card or a popover that already draws a box.
  • Set minuteStep to what the schedule books, 5 or 15. Sixty rows of minutes make a long wheel for a choice that has four answers.
  • Leave hourCycle to the locale unless the product fixes one. A clinic that prints 24-hour times everywhere should ask for them here too.
  • Ask for seconds with granularity="second" only when they mean something, as in a lab log.

Accessibility

  • Each wheel is a role="spinbutton" with its value, its text and its limits, so a screen reader reads "9 hours" and not a list of numbers.
  • Up and Down step the focused wheel, Home and End go to its first and last value, and Left and Right move between the wheels.
  • label names the clock through aria-labelledby. Without it, give the clock an aria-label.
  • The keyboard focus is drawn inside the chosen row, as a ring outside it would be cut by the scroll of the wheel.
  • disabled takes every wheel out of the tab order and dims the clock.

API reference

PropTypeDefault
valuestring | null

The time, as HH:mm or HH:mm:ss on 24 hours. Bindable.

—
defaultValuestring | null

The time at the start, when no value is given.

—
onChange(value: string | null) => void

Runs each time a wheel settles on a new value.

—
variant'outline' | 'filled' | 'ghost'

A card of its own around the wheels, a soft grey, or the wheels straight on the surface.

'outline'
labelstring

The name over the clock.

—
granularity'hour' | 'minute' | 'second'

The smallest unit it asks for. hour gives values as HH:00.

'minute'
hourCycle12 | 24

Hours to 12 with a day-period wheel, or to 24. Without it, the locale decides.

—
hourStepnumber

The step between the hours of the wheel.

1
minuteStepnumber

The step between the minutes of the wheel.

1
secondStepnumber

The step between the seconds of the wheel.

1
minValuestring

The earliest time it takes, as HH:mm. Limits do not wrap past midnight.

—
maxValuestring

The latest time it takes, as HH:mm.

—
disabledboolean

Turns every wheel off.

false

class styles the outer box, with the label. Every other attribute of a <div>, aria-label among them, goes on the element that holds the wheels.