TimePicker
TimePicker chooses a time of day in columns of hours, minutes and seconds. TimeRangePicker chooses a start and an end. The values are native Date objects.
When to use
- Use a time picker when a person chooses a time of day: the start of a meeting, opening hours, an alarm.
- Steps and disabled times narrow the columns to what can really be chosen; a person who knows the time can type it.
- Use
TimeRangePickerfor a start and an end that belong together, andDatePickerwithshowTimewhen the day matters too.
Examples
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
let start = $state<Date | null>(null);
const clock = (time: Date | null) => (time ? time.toTimeString().slice(0, 8) : 'nothing');
</script>
<div class="stack">
<div class="field">
<TimePicker aria-label="Start" bind:value={start} />
<span role="status">Value: {clock(start)}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
</style>
format="HH:mm": two columns
14:05
format="HH": the hour alone
a list: the first writes, each reads (try 7.30)
a function writes; nothing typed is read
14 h 5 min
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
const moment = new Date(2026, 0, 1, 14, 5, 9);
</script>
<div class="stack">
<div class="field">
<span class="caption">format="HH:mm": two columns</span>
<TimePicker aria-label="Hours and minutes" format="HH:mm" value={moment} />
</div>
<div class="field">
<span class="caption">format="HH": the hour alone</span>
<TimePicker aria-label="Hour" format="HH" />
</div>
<div class="field">
<span class="caption">a list: the first writes, each reads (try 7.30)</span>
<TimePicker aria-label="Either way" format={['HH:mm', 'H.mm']} />
</div>
<div class="field">
<span class="caption">a function writes; nothing typed is read</span>
<TimePicker aria-label="In words" format={(time) => `${time.getHours()} h ${time.getMinutes()} min`} value={moment} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
use12Hours: h:mm:ss a
2:05:09 pm
format="h:mm A"
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
const moment = new Date(2026, 0, 1, 14, 5, 9);
</script>
<div class="stack">
<div class="field">
<span class="caption">use12Hours: h:mm:ss a</span>
<TimePicker aria-label="Twelve hours" use12Hours value={moment} />
</div>
<div class="field">
<span class="caption">format="h:mm A"</span>
<TimePicker aria-label="Twelve hours without seconds" format="h:mm A" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
every 2 hours, 15 minutes and 30 seconds
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">every 2 hours, 15 minutes and 30 seconds</span>
<TimePicker aria-label="In steps" hourStep={2} minuteStep={15} secondStep={30} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
disabledTime: open from 9:00 to 18:30
hideDisabledOptions: they are not shown
<script lang="ts">
import { TimePicker, type DisabledTimes } from 'svelte-ant-design';
const range = (from: number, to: number) => Array.from({ length: to - from }, (_, index) => from + index);
// Open from 9 to 18; in the last hour only the first half.
const openingHours = (): DisabledTimes => ({
disabledHours: () => [...range(0, 9), ...range(19, 24)],
disabledMinutes: (hour) => (hour === 18 ? range(31, 60) : [])
});
</script>
<div class="stack">
<div class="field">
<span class="caption">disabledTime: open from 9:00 to 18:30</span>
<TimePicker aria-label="Visit" format="HH:mm" disabledTime={openingHours} />
</div>
<div class="field">
<span class="caption">hideDisabledOptions: they are not shown</span>
<TimePicker aria-label="Visit, short list" format="HH:mm" disabledTime={openingHours} hideDisabledOptions />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
the value waits for OK; onok says it was confirmed
needConfirm=false: every choice is taken Value: nothing
showNow=false, defaultOpenValue 09:00
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
let taken = $state<Date | null>(null);
let confirmed = $state('');
const nine = new Date(2026, 0, 1, 9, 0);
const clock = (time: Date | null) => (time ? time.toTimeString().slice(0, 8) : 'nothing');
</script>
<div class="stack">
<div class="field">
<span class="caption">the value waits for OK; onok says it was confirmed</span>
<TimePicker aria-label="Confirmed time" onok={(time) => (confirmed = clock(time))} />
{#if confirmed}<span role="status">Confirmed: {confirmed}</span>{/if}
</div>
<div class="field">
<span class="caption">needConfirm=false: every choice is taken</span>
<TimePicker aria-label="Taken at once" needConfirm={false} bind:value={taken} />
<span role="status">Value: {clock(taken)}</span>
</div>
<div class="field">
<span class="caption">showNow=false, defaultOpenValue 09:00</span>
<TimePicker aria-label="From nine" showNow={false} defaultOpenValue={nine} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
changeOnScroll with needConfirm=false: scroll a column Value: nothing
changeOnScroll: the scrolled time waits for OK
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
let taken = $state<Date | null>(null);
const clock = (time: Date | null) => (time ? time.toTimeString().slice(0, 8) : 'nothing');
</script>
<div class="stack">
<div class="field">
<span class="caption">changeOnScroll with needConfirm=false: scroll a column</span>
<TimePicker aria-label="Scrolled" changeOnScroll needConfirm={false} bind:value={taken} />
<span role="status">Value: {clock(taken)}</span>
</div>
<div class="field">
<span class="caption">changeOnScroll: the scrolled time waits for OK</span>
<TimePicker aria-label="Scrolled and confirmed" changeOnScroll />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { TimeRangePicker, type DateRange } from 'svelte-ant-design';
let shift = $state<DateRange | null>(null);
let last = $state('');
const clock = (time: Date | null) => (time ? time.toTimeString().slice(0, 5) : 'empty');
</script>
<div class="stack">
<div class="field">
<TimeRangePicker
aria-label="Shift"
format="HH:mm"
bind:value={shift}
oncalendarchange={(_, text, { range }) => (last = `${range}: ${text[range === 'start' ? 0 : 1]}`)}
/>
<span role="status">{shift ? `${clock(shift[0])} – ${clock(shift[1])}` : 'No shift chosen'}</span>
{#if last}<span role="status">Last end chosen, {last}</span>{/if}
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
</style>
order=false: a night shift ends before it starts
allowEmpty: the end may stay empty
disabled={[true, false]}: the start is fixed
09:00 18:00
disabledTime is told which end it is asked for
<script lang="ts">
import { TimeRangePicker, type DisabledTimes, type RangeEnd } from 'svelte-ant-design';
const opening: [Date, Date] = [new Date(2026, 0, 1, 9, 0), new Date(2026, 0, 1, 18, 0)];
// A start in the morning, an end in the afternoon.
const halves = (_: Date | null, end: RangeEnd): DisabledTimes => ({
disabledHours: () => Array.from({ length: 12 }, (_, hour) => (end === 'start' ? hour + 12 : hour))
});
let open = $state('');
</script>
<div class="stack">
<div class="field">
<span class="caption">order=false: a night shift ends before it starts</span>
<TimeRangePicker aria-label="Night shift" format="HH:mm" order={false} separator="to" id={{ start: 'night-from', end: 'night-to' }} />
</div>
<div class="field">
<span class="caption">allowEmpty: the end may stay empty</span>
<TimeRangePicker
aria-label="Opening"
format="HH:mm"
allowEmpty={[false, true]}
placeholder={['Opens', 'Closes (optional)']}
inputLabels={['Opening time', 'Closing time']}
onchange={(_, text) => (open = text.map((part) => part || 'open').join(' – '))}
/>
{#if open}<span role="status">{open}</span>{/if}
</div>
<div class="field">
<span class="caption">{'disabled={[true, false]}'}: the start is fixed</span>
<TimeRangePicker aria-label="Longer day" format="HH:mm" disabled={[true, false]} value={opening} />
</div>
<div class="field">
<span class="caption">disabledTime is told which end it is asked for</span>
<TimeRangePicker aria-label="Two halves" format="HH:mm" disabledTime={halves} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { TimeRangePicker } from 'svelte-ant-design';
const at = (hour: number, minute = 0) => new Date(2026, 0, 1, hour, minute);
const presets = [
{ label: 'Morning', value: [at(9), at(13)] as [Date, Date] },
{ label: 'Evening', value: [at(14), at(18)] as [Date, Date] }
];
</script>
<div class="stack">
<div class="field">
<TimeRangePicker aria-label="Meeting hours" format="HH:mm" {presets} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
</style>
disabled
14:30:00
inputReadOnly: chosen in the panel only
14:30:00
allowClear=false
14:30:00
allowClear with its own icon and name
14:30:00
placeholder
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
const moment = new Date(2026, 0, 1, 14, 30);
</script>
<div class="stack">
<div class="field">
<span class="caption">disabled</span>
<TimePicker aria-label="Disabled time" disabled value={moment} />
</div>
<div class="field">
<span class="caption">inputReadOnly: chosen in the panel only</span>
<TimePicker aria-label="Chosen only" inputReadOnly value={moment} />
</div>
<div class="field">
<span class="caption">allowClear=false</span>
<TimePicker aria-label="Always set" allowClear={false} value={moment} />
</div>
<div class="field">
<span class="caption">allowClear with its own icon and name</span>
<TimePicker aria-label="Reset" allowClear={{ label: 'Reset the time', clearIcon: '↺' }} value={moment} />
</div>
<div class="field">
<span class="caption">placeholder</span>
<TimePicker aria-label="Alarm" placeholder="Wake me at" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
large
medium
small
<script lang="ts">
import { TimePicker, TimeRangePicker } from 'svelte-ant-design';
const sizes = ['large', 'medium', 'small'] as const;
</script>
<div class="stack">
{#each sizes as size (size)}
<div class="field">
<span class="caption">{size}</span>
<TimePicker aria-label="Time, {size}" {size} />
<TimeRangePicker aria-label="Range, {size}" {size} />
</div>
{/each}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
outlined
filled
borderless
underlined
<script lang="ts">
import { TimePicker, TimeRangePicker } from 'svelte-ant-design';
const variants = ['outlined', 'filled', 'borderless', 'underlined'] as const;
</script>
<div class="stack">
{#each variants as variant (variant)}
<div class="field">
<span class="caption">{variant}</span>
<TimePicker aria-label="Time, {variant}" {variant} />
<TimeRangePicker aria-label="Range, {variant}" {variant} />
</div>
{/each}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<TimePicker aria-label="Time with an error" status="error" aria-describedby="time-error" />
<span id="time-error">Choose a time during opening hours.</span>
</div>
<div class="field">
<TimePicker aria-label="Time with a warning" status="warning" aria-describedby="time-warning" />
<span id="time-warning">The office is busy at this hour.</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
</style>
prefix
From
suffix replaces the clock
UTC
suffix={null}: no icon
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">prefix</span>
<TimePicker aria-label="Departure" prefix="From" />
</div>
<div class="field">
<span class="caption">suffix replaces the clock</span>
<TimePicker aria-label="Arrival" suffix="UTC" />
</div>
<div class="field">
<span class="caption">{'suffix={null}'}: no icon</span>
<TimePicker aria-label="Plain" suffix={null} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
cellRender: the full quarters are marked; extraFooter as a text
extraFooter as a snippet
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">cellRender: the full quarters are marked; extraFooter as a text</span>
<TimePicker aria-label="Quarter" format="HH:mm" extraFooter="Times of the local zone">
{#snippet cellRender({ column, value, text })}
<span class:quarter={column === 'minute' && value % 15 === 0}>{text}</span>
{/snippet}
</TimePicker>
</div>
<div class="field">
<span class="caption">extraFooter as a snippet</span>
<TimePicker aria-label="With a note">
{#snippet extraFooter()}<strong>Closed on Sundays</strong>{/snippet}
</TimePicker>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.quarter {
text-decoration: underline 2px var(--ads-color-primary);
text-underline-offset: 3px;
}
</style>
open held by the page Opened by the field 0 times
placement="topRight"
container: the panel is drawn inside the box
<script lang="ts">
import { Button, TimePicker } from 'svelte-ant-design';
let open = $state(false);
let opened = $state(0);
let box = $state<HTMLDivElement>();
</script>
<div class="stack">
<div class="field">
<span class="caption">open held by the page</span>
<TimePicker aria-label="Controlled panel" bind:open onopenchange={(next) => next && opened++} />
<Button onclick={() => (open = true)}>Open the panel</Button>
<span role="status">Opened by the field {opened} times</span>
</div>
<div class="field">
<span class="caption">placement="topRight"</span>
<TimePicker aria-label="Above the field" placement="topRight" />
</div>
<div class="field">
<span class="caption">container: the panel is drawn inside the box</span>
<div class="box" bind:this={box}>
<TimePicker aria-label="Inside the box" container={() => box ?? document.body} />
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
position: relative;
justify-self: stretch;
padding: 12px;
border: 1px dashed var(--ads-color-border);
}
</style>
ru, with the halves of the day in words
9:05 утра
zh-cn
上午9:05
ru, a range
<script lang="ts">
import { TimePicker, TimeRangePicker } from 'svelte-ant-design';
import ru from 'svelte-ant-design/locales/ru';
import zhCn from 'svelte-ant-design/locales/zh-cn';
const moment = new Date(2026, 0, 1, 9, 5);
</script>
<div class="stack">
<div class="field">
<span class="caption">ru, with the halves of the day in words</span>
<TimePicker aria-label="Время" locale={ru} format="h:mm A" value={moment} />
</div>
<div class="field">
<span class="caption">zh-cn</span>
<TimePicker aria-label="时间" locale={zhCn} format="Ah:mm" value={moment} />
</div>
<div class="field">
<span class="caption">ru, a range</span>
<TimeRangePicker aria-label="Смена" locale={ru} format="HH:mm" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(320px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
let log = $state<string[]>([]);
const note = (line: string) => (log = [line, ...log].slice(0, 4));
</script>
<div class="stack">
<div class="field">
<TimePicker
aria-label="Watched time"
onchange={(_, text) => note(`onchange: ${text || 'empty'}`)}
onclear={() => note('onclear')}
onfocus={() => note('onfocus')}
onblur={() => note('onblur')}
/>
<ul class="log" aria-live="polite">
{#each log as line, index (index)}<li>{line}</li>{/each}
</ul>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.log {
min-height: 5.5em;
margin: 0;
padding-inline-start: 18px;
}
</style>
Departure
<script lang="ts">
import { Button, Select, SpaceCompact, TimePicker } from 'svelte-ant-design';
let kind = $state('Departure');
</script>
<div class="stack">
<div class="field">
<SpaceCompact block>
<Select aria-label="Kind of time" bind:value={kind} options={['Departure', 'Arrival']} style="width: 140px" />
<TimePicker aria-label="Time of the trip" />
<Button type="primary">Search</Button>
</SpaceCompact>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(420px, 100%);
}
</style>
classNames and styles
<script lang="ts">
import { TimePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">classNames and styles</span>
<TimePicker
aria-label="Styled time"
class="rounded"
style="max-width: 240px"
classNames={{ popup: 'soft', input: 'strong', cell: 'digit' }}
styles={{ root: { 'border-radius': '16px' }, suffix: { color: 'var(--ads-color-primary)' } }}
/>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(240px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
:global(.rounded .strong) {
font-weight: 600;
}
:global(.soft .digit) {
font-variant-numeric: tabular-nums;
font-weight: 500;
}
</style>
API
| Property | Description | Type | Default |
|---|---|---|---|
| value | The chosen time, on a date. Bind it with bind:value. | Date | null | null |
| format | How the time is written; with a list the first writes and each reads. The pattern decides the columns. With use12Hours the default is h:mm:ss a. | string | string[] | (date: Date) => string | 'HH:mm:ss' |
| use12Hours | Hours from 1 to 12 and a column of AM and PM. | boolean | false |
| hourStep | Every n-th hour. | number | 1 |
| minuteStep | Every n-th minute. | number | 1 |
| secondStep | Every n-th second. | number | 1 |
| disabledTime | Hours, minutes and seconds that cannot be chosen; the argument is the time chosen or judged, null before one is chosen. | (date: Date | null) => DisabledTimes | — |
| hideDisabledOptions | Disabled numbers are not shown. | boolean | false |
| defaultOpenValue | The time and the date a choice starts from; today at 00:00:00 without it. | Date | — |
| needConfirm | The value changes on OK only. | boolean | true |
| showNow | The "Now" button. | boolean | true |
| changeOnScroll | The number a column comes to rest on, after the user scrolled it, is chosen. | boolean | false |
| cellRender | The content of a number: { column, value, text, selected, disabled, range }. | Snippet<[cell: TimeCell]> | — |
| extraFooter | Under the columns. | string | Snippet | — |
| placeholder | The hint of the empty field; by default from the locale. | string | — |
| disabled | The field cannot be used. | boolean | false |
| inputReadOnly | The field cannot be typed in; a phone shows no keyboard. | boolean | false |
| allowClear | A button that empties the value; an object changes its icon, name and tabindex. | boolean | { clearIcon?, label?, tabIndex? } | true |
| size | medium unless a SpaceCompact says otherwise; middle and default are aliases. | 'large' | 'medium' | 'middle' | 'small' | 'default' | — |
| variant | The look of the field. | 'outlined' | 'filled' | 'borderless' | 'underlined' | 'outlined' |
| status | Paints an error or a warning; error also sets aria-invalid. | 'error' | 'warning' | — |
| prefix | Before the text. | string | Snippet | — |
| suffix | Replaces the clock icon; null hides it. | string | Snippet | null | — |
| open | Whether the panel is shown. Bind it with bind:open. | boolean | false |
| placement | The side the panel prefers; it flips at the edge of the screen. | 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight' | 'bottomLeft' |
| container | Where the panel is put (default: the end of <body>). | HTMLElement | (anchor) => HTMLElement | — |
| locale | The texts and the names of AM and PM: import ru from 'svelte-ant-design/locales/ru'. | DatePickerLocale | en |
| onchange | The user changed the value; the second argument is the text. | (value, text: string) => void | — |
| onok | A time was confirmed with OK or Enter, with needConfirm. | (value: Date) => void | — |
| onopenchange | The panel opened or closed. | (open: boolean) => void | — |
| onclear | The clear button emptied the value. | () => void | — |
| onfocus | The focus came to the field or its panel from outside. | (event: FocusEvent) => void | — |
| onblur | The focus left both. | (event: FocusEvent) => void | — |
| classNames | Extra classes of root, input, prefix, suffix, popup, body, cell and footer. | TimePickerClassNames | — |
| styles | Inline styles of the same parts. | TimePickerStyles | — |
| class / style | Class and style of the field. | string | — |
| native attributes | The other attributes go to the <input> (id, name, aria-*, autofocus). | HTMLInputAttributes | — |
Differences from Ant Design: values are native
Date objects, not dayjs; TimePicker.RangePicker is TimeRangePicker; the focus alone does not open the panel; the keyboard follows the ARIA combobox and listbox patterns; a range has a "Now" button. Not in this version: milliseconds, a masked format, previewValue, panelRender, footer buttons of your own, presets of a single TimePicker and another date library.TimeRangePicker
TimeRangePicker takes the props of TimePicker; these differ or are its own.
| Property | Description | Type | Default |
|---|---|---|---|
| value | The start and the end; an end not chosen is null. Bind it with bind:value. | [Date | null, Date | null] | null | null |
| placeholder | The hints of the two inputs; by default from the locale. | [string, string] | — |
| inputLabels | The accessible names of the two inputs; by default from the locale. | [string, string] | — |
| disabled | Both ends, or each. A disabled end keeps its value and fixes the order. | boolean | [boolean, boolean] | false |
| allowEmpty | An end that may stay empty. | [boolean, boolean] | [false, false] |
| separator | Between the inputs; an arrow by default. | string | Snippet | — |
| order | The start is not after the end, by the time of day: two ends chosen now swap, an end kept from before is asked again. | boolean | true |
| id | The ids of the two inputs. | { start?: string; end?: string } | — |
| autofocus | The start input takes the focus when the page loads. | boolean | false |
| disabledTime | Times that cannot be chosen, for the end asked. | (date: Date | null, range: 'start' | 'end') => DisabledTimes | — |
| presets | Quick choices that give both ends. | { label: string | Snippet; value: [Date, Date] | (() => [Date, Date]) }[] | [] |
| onchange | The range changed: once, when it is complete. | (value, text: [string, string]) => void | — |
| oncalendarchange | An end was chosen; range says which. | (value, text, info: { range }) => void | — |
| onok | A range was confirmed with OK or Enter, with needConfirm. | (value) => void | — |
| onfocus | The focus came to the field or its panel from outside. | (event, info: { range }) => void | — |
| onblur | The focus left both. | (event, info: { range }) => void | — |
| native attributes | The other attributes go to the root, a group: aria-label, data-*. | HTMLAttributes<HTMLDivElement> | — |
Methods
| Method | Description | Type |
|---|---|---|
| focus | Moves focus to the field; in a range, to the end that is asked. The panel does not open. | (options?: FocusOptions) => void |
| blur | Removes focus from the field; the panel closes. | () => void |
Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-time-picker-column-height | Height of the columns. | 224px |
| --ads-picker-time-column-width | Width of a column. | 56px |
| --ads-picker-time-item-height | Height of a number. | 28px |
| --ads-picker-time-selected-bg | The chosen number. | #e6f4ff |
| --ads-picker-cell-hover-bg | A number under the pointer. | rgba(0, 0, 0, 0.04) |
| --ads-picker-popup-radius | Corner radius of the panel. | 8px |
| --ads-picker-popup-bg | Background of the panel. | #ffffff |
| --ads-picker-popup-shadow | Shadow of the panel. | 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-picker-actions-height | Least height of the buttons under the columns. | 42px |
| --ads-picker-presets-width | Width of the column of quick choices. | 120px |
| --ads-picker-icon-color | The icons of the field. | rgba(0, 0, 0, 0.45) |
Keyboard
Arrow Downin the field opens the panel and moves the focus to the first column.- In a column
UpandDownchange the number,HomeandEndgo to its ends,LeftandRightto the column beside. EnterorSpacechooses a number;Enteron the chosen one confirms what waits for OK. In a range the focus then goes to the input of the other end.Escapecloses the panel, drops what was not confirmed and returns the focus to the field.Tableaves the field and closes the panel; in a range it goes from the start to the end first. In the panel it walks the columns (one stop each) and the footer.
Accessibility
- The field is a
comboboxthat names its dialog; each column is alistboxwith a name, and its numbers are options that say what is chosen and what is disabled. - A range is a
groupwith two named inputs; the dialog says which end it asks for. Give the group a name witharia-label. - The default light colors follow Ant Design and not all reach a contrast of 4.5:1; load
tokens-accessible.cssfor them. The chosen and disabled numbers stay visible in forced colors. - Checked with a real screen reader (Orca with Firefox): it reads the field, the name of the dialog, the columns and their numbers, the value after it is confirmed and the ends of a range. Orca does not say the value of such a field by itself, so every input also gives it as its description: NVDA, JAWS and VoiceOver, not checked, may say it twice. Orca does not say that a number is disabled, and for the
Enterthat chooses a number it says only the key. Not checked with NVDA, JAWS, VoiceOver or on a phone.