DatePicker
DatePicker chooses a date, a week, a month, a quarter or a year, with a time or several at once. DateRangePicker chooses a start and an end. The values are native Date objects.
When to use
- Use a picker when a person chooses a date and the calendar helps: a delivery day, a stay, a period of a report.
- For a date that a person knows by heart, such as a birthday, typing works too: the field reads the text by
format. - Use
DateRangePickerfor two dates that belong together, not two separate pickers.
Examples
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
let date = $state<Date | null>(null);
</script>
<div class="stack">
<div class="field">
<DatePicker aria-label="Date" bind:value={date} />
<span role="status">Chosen: {date ? date.toDateString() : 'nothing'}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(260px, 100%);
}
</style>
picker="week"
picker="month"
picker="quarter"
picker="year"
<script lang="ts">
import { DatePicker, type PickerType } from 'svelte-ant-design';
const pickers: PickerType[] = ['week', 'month', 'quarter', 'year'];
</script>
<div class="stack">
{#each pickers as picker (picker)}
<div class="field">
<span class="caption">picker="{picker}"</span>
<DatePicker aria-label="Choose a {picker}" {picker} />
</div>
{/each}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(260px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
format="DD.MM.YYYY"
02.12.2026
format as a list: the first writes, each one reads
2 Dec 2026
format as a function
Wednesday, 2 December 2026
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
const today = new Date();
const long = (date: Date) => date.toLocaleDateString('en-GB', { dateStyle: 'full' });
</script>
<div class="stack">
<div class="field">
<span class="caption">format="DD.MM.YYYY"</span>
<DatePicker aria-label="Day, month, year" format="DD.MM.YYYY" value={today} />
</div>
<div class="field">
<span class="caption">format as a list: the first writes, each one reads</span>
<DatePicker aria-label="Several formats" format={['D MMM YYYY', 'DD/MM/YYYY', 'YYYY-MM-DD']} value={today} />
</div>
<div class="field">
<span class="caption">format as a function</span>
<DatePicker aria-label="Long date" format={long} value={today} inputReadOnly />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
showTime: the value waits for OK Value: nothing
12 hours, steps of 15 minutes, no seconds
needConfirm=false, showNow=false Value: nothing
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
let moment = $state<Date | null>(null);
let instant = $state<Date | null>(null);
const nine = new Date(2026, 0, 1, 9, 0);
</script>
<div class="stack">
<div class="field">
<span class="caption">showTime: the value waits for OK</span>
<DatePicker aria-label="Date and time" showTime bind:value={moment} />
<span role="status">Value: {moment ? moment.toString().slice(0, 24) : 'nothing'}</span>
</div>
<div class="field">
<span class="caption">12 hours, steps of 15 minutes, no seconds</span>
<DatePicker aria-label="Meeting" showTime={{ use12Hours: true, minuteStep: 15, showSecond: false, defaultOpenValue: nine }} />
</div>
<div class="field">
<span class="caption">needConfirm=false, showNow=false</span>
<DatePicker
aria-label="Taken at once"
showTime={{ format: 'HH:mm:ss', hourStep: 2, secondStep: 30 }}
needConfirm={false}
showNow={false}
bind:value={instant}
/>
<span role="status">Value: {instant ? instant.toString().slice(0, 24) : 'nothing'}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
disabledDate: working days only
minDate and maxDate: the rest of this month
disabledTime: 9:00 to 17:59
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
const today = new Date();
const monthEnd = new Date(today.getFullYear(), today.getMonth() + 1, 0);
const weekend = (date: Date) => date.getDay() === 0 || date.getDay() === 6;
const officeHours = () => ({
disabledHours: () => Array.from({ length: 24 }, (_, hour) => hour).filter((hour) => hour < 9 || hour > 17)
});
</script>
<div class="stack">
<div class="field">
<span class="caption">disabledDate: working days only</span>
<DatePicker aria-label="Working day" disabledDate={(date, { type }) => type === 'date' && weekend(date)} />
</div>
<div class="field">
<span class="caption">minDate and maxDate: the rest of this month</span>
<DatePicker aria-label="This month" minDate={today} maxDate={monthEnd} />
</div>
<div class="field">
<span class="caption">disabledTime: 9:00 to 17:59</span>
<DatePicker
aria-label="Office hours"
showTime={{ format: 'HH:mm', hideDisabledOptions: true }}
disabledTime={officeHours}
/>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
needConfirm, onok, extraFooter
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
let value = $state<Date | null>(null);
let confirmed = $state('');
</script>
<div class="stack">
<div class="field">
<span class="caption">needConfirm, onok, extraFooter</span>
<DatePicker
aria-label="Delivery day"
needConfirm
extraFooter="Deliveries take two working days"
bind:value
onok={(date) => (confirmed = date.toDateString())}
/>
{#if confirmed}<span role="status">Confirmed: {confirmed}</span>{/if}
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
const inDays = (days: number) => () => {
const today = new Date();
return new Date(today.getFullYear(), today.getMonth(), today.getDate() + days);
};
const presets = [
{ label: 'Tomorrow', value: inDays(1) },
{ label: 'In a week', value: inDays(7) },
{ label: 'In a month', value: inDays(30) }
];
let date = $state<Date | null>(null);
</script>
<div class="stack">
<div class="field">
<DatePicker aria-label="Due date" {presets} bind:value={date} />
<span role="status">Due: {date ? date.toDateString() : 'not set'}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(260px, 100%);
}
</style>
multiple, order=true 2 chosen
2026-01-05 2026-01-07 2026-01-05, 2026-01-07
maxTagCount=2, maxTagPlaceholder
2026-01-05 2026-01-07 and 3 more 2026-01-05, 2026-01-07, 2026-01-09, 2026-01-11, 2026-01-13
maxTagCount="responsive": one row
2026-01-05 2026-01-07 2026-01-09 2026-01-11 2026-01-13 2026-01-15 2026-01-17 2026-01-19 + 1 ... 2026-01-05, 2026-01-07, 2026-01-09, 2026-01-11, 2026-01-13, 2026-01-15, 2026-01-17, 2026-01-19
tagRender
5 Jan, 7 Jan, 9 Jan
<script lang="ts">
import { DatePicker, Switch } from 'svelte-ant-design';
const days = (count: number) => Array.from({ length: count }, (_, index) => new Date(2026, 0, 5 + index * 2));
let dates = $state<Date[]>(days(2));
let sorted = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">multiple, order={sorted}</span>
<label class="row"><Switch bind:checked={sorted} aria-label="Keep the dates sorted" /> order</label>
<DatePicker aria-label="Training days" multiple order={sorted} bind:value={dates} />
<span role="status">{dates.length} chosen</span>
</div>
<div class="field">
<span class="caption">maxTagCount=2, maxTagPlaceholder</span>
<DatePicker aria-label="Two tags" multiple maxTagCount={2} value={days(5)}>
{#snippet maxTagPlaceholder(omitted)}and {omitted.length} more{/snippet}
</DatePicker>
</div>
<div class="field">
<span class="caption">maxTagCount="responsive": one row</span>
<DatePicker aria-label="One row" multiple maxTagCount="responsive" value={days(8)} />
</div>
<div class="field">
<span class="caption">tagRender</span>
<DatePicker aria-label="Own tags" multiple format="D MMM" value={days(3)}>
{#snippet tagRender({ label, closable, onclose })}
<button type="button" class="chip" disabled={!closable} onclick={onclose} aria-label="Remove {label}">{label} ×</button>
{/snippet}
</DatePicker>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(300px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.row {
display: flex;
align-items: center;
gap: 8px;
}
.chip {
margin-inline-end: 4px;
padding: 0 6px;
border: 1px solid var(--ads-color-primary);
border-radius: 10px;
background: none;
color: var(--ads-color-text);
font: inherit;
font-size: 12px;
cursor: pointer;
}
</style>
<script lang="ts">
import { DateRangePicker, type DateRange } from 'svelte-ant-design';
let stay = $state<DateRange | null>(null);
let last = $state('');
const day = (date: Date | null) => (date ? date.toDateString() : 'empty');
</script>
<div class="stack">
<div class="field">
<DateRangePicker
aria-label="Stay"
bind:value={stay}
oncalendarchange={(value, text, { range }) => (last = `${range}: ${text[range === 'start' ? 0 : 1]}`)}
/>
<span role="status">{stay ? `${day(stay[0])} – ${day(stay[1])}` : 'No stay 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(360px, 100%);
}
</style>
picker="month"
showTime: each end waits for OK
presets
<script lang="ts">
import { DateRangePicker, type DateRange } from 'svelte-ant-design';
let shift = $state<DateRange | null>(null);
let confirmed = $state('');
const lastDays = (days: number) => (): [Date, Date] => {
const end = new Date();
return [new Date(end.getFullYear(), end.getMonth(), end.getDate() - days + 1), end];
};
const presets = [
{ label: 'Last 7 days', value: lastDays(7) },
{ label: 'Last 30 days', value: lastDays(30) }
];
</script>
<div class="stack">
<div class="field">
<span class="caption">picker="month"</span>
<DateRangePicker aria-label="Months of the report" picker="month" />
</div>
<div class="field">
<span class="caption">showTime: each end waits for OK</span>
<DateRangePicker
aria-label="Shift"
showTime={{ format: 'HH:mm' }}
bind:value={shift}
onok={(value) => (confirmed = `${value[0]?.getHours()}:00 to ${value[1]?.getHours()}:00`)}
/>
{#if confirmed}<span role="status">Hours confirmed: {confirmed}</span>{/if}
</div>
<div class="field">
<span class="caption">presets</span>
<DateRangePicker aria-label="Period" {presets} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(380px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
allowEmpty: the end may stay empty
disabled={[true, false]}: the start is fixed
2026-01-12 2026-01-16
disabledDate with from: seven days at most
order=false, separator, id
<script lang="ts">
import { DateRangePicker } from 'svelte-ant-design';
const booked: [Date, Date] = [new Date(2026, 0, 12), new Date(2026, 0, 16)];
const dayLength = 24 * 60 * 60 * 1000;
// Seven days at most, counting both ends: once one end is chosen, the other is six days from it or nearer. The days are
// rounded, because a day on which the clocks change is not 24 hours long.
const withinWeek = (date: Date, { from }: { from?: Date }) =>
from !== undefined && Math.round(Math.abs(date.getTime() - from.getTime()) / dayLength) > 6;
let changed = $state('');
</script>
<div class="stack">
<div class="field">
<span class="caption">allowEmpty: the end may stay empty</span>
<DateRangePicker
aria-label="Contract"
allowEmpty={[false, true]}
placeholder={['Signed', 'Ends (optional)']}
inputLabels={['Date of signing', 'Date of the end']}
onchange={(value, text) => (changed = text.map((part) => part || 'open').join(' – '))}
/>
{#if changed}<span role="status">{changed}</span>{/if}
</div>
<div class="field">
<span class="caption">{'disabled={[true, false]}'}: the start is fixed</span>
<DateRangePicker aria-label="Extension" disabled={[true, false]} value={booked} />
</div>
<div class="field">
<span class="caption">disabledDate with from: seven days at most</span>
<DateRangePicker aria-label="Short trip" disabledDate={withinWeek} />
</div>
<div class="field">
<span class="caption">order=false, separator, id</span>
<DateRangePicker aria-label="Night shift" order={false} separator="to" id={{ start: 'shift-from', end: 'shift-to' }} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(360px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
disabled
2026-12-02
inputReadOnly: no typing, no keyboard on a phone
allowClear=false
2026-12-02
allowClear with an icon and a name
2026-12-02
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
const today = new Date();
</script>
<div class="stack">
<div class="field">
<span class="caption">disabled</span>
<DatePicker aria-label="Disabled" disabled value={today} />
</div>
<div class="field">
<span class="caption">inputReadOnly: no typing, no keyboard on a phone</span>
<DatePicker aria-label="Read-only input" inputReadOnly placeholder="Pick on the calendar" />
</div>
<div class="field">
<span class="caption">allowClear=false</span>
<DatePicker aria-label="No clear button" allowClear={false} value={today} />
</div>
<div class="field">
<span class="caption">allowClear with an icon and a name</span>
<DatePicker aria-label="Own clear button" allowClear={{ clearIcon: '×', label: 'Forget the date' }} value={today} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
size="large"
size="medium"
size="small"
<script lang="ts">
import { DatePicker, DateRangePicker } 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="{size}"</span>
<DatePicker aria-label="{size} date" {size} />
<DateRangePicker aria-label="{size} range" {size} />
</div>
{/each}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(340px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
variant="outlined"
variant="filled"
variant="borderless"
variant="underlined"
<script lang="ts">
import { DatePicker } 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="{variant}"</span>
<DatePicker aria-label="{variant} date" {variant} />
</div>
{/each}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(260px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
status="error" Choose your birthday.
status="warning" These days are almost fully booked.
<script lang="ts">
import { DatePicker, DateRangePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">status="error"</span>
<DatePicker aria-label="Birthday" status="error" />
<span class="hint">Choose your birthday.</span>
</div>
<div class="field">
<span class="caption">status="warning"</span>
<DateRangePicker aria-label="Holiday" status="warning" />
<span class="hint">These days are almost fully booked.</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(340px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.hint {
color: var(--ads-color-text-secondary);
}
</style>
prefix and suffix
From ✈
suffix=null: no icon
prevIcon, nextIcon, superPrevIcon, superNextIcon
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">prefix and suffix</span>
<DatePicker aria-label="Flight" prefix="From" suffix="✈" />
</div>
<div class="field">
<span class="caption">suffix=null: no icon</span>
<DatePicker aria-label="No icon" suffix={null} />
</div>
<div class="field">
<span class="caption">prevIcon, nextIcon, superPrevIcon, superNextIcon</span>
<DatePicker aria-label="Own arrows">
{#snippet prevIcon()}‹{/snippet}
{#snippet nextIcon()}›{/snippet}
{#snippet superPrevIcon()}«{/snippet}
{#snippet superNextIcon()}»{/snippet}
</DatePicker>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
cellRender: the paydays are underlined
<script lang="ts">
import { DatePicker } from 'svelte-ant-design';
const payday = (date: Date) => date.getDate() === 5 || date.getDate() === 20;
</script>
<div class="stack">
<div class="field">
<span class="caption">cellRender: the paydays are underlined</span>
<DatePicker aria-label="Payday">
{#snippet cellRender({ date, type, inView, text })}
<span class:payday={type === 'date' && inView && payday(date)}>{text}</span>
{/snippet}
</DatePicker>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.payday {
text-decoration: underline 2px var(--ads-color-primary);
text-underline-offset: 3px;
}
</style>
open and pickerValue held by the page Opened 0 times
showWeek and placement="bottomRight"
mode="year": the panel stays on the years
container: the panel is drawn inside the box
<script lang="ts">
import { Button, DatePicker, type PanelMode } from 'svelte-ant-design';
let open = $state(false);
let shownPeriod = $state(new Date(2026, 5, 1));
let moved = $state('');
let opened = $state(0);
let box = $state<HTMLDivElement>();
const describe = (value: Date, mode: PanelMode) => `${mode} panel, ${value.getFullYear()}-${value.getMonth() + 1}`;
</script>
<div class="stack">
<div class="field">
<span class="caption">open and pickerValue held by the page</span>
<DatePicker
aria-label="Controlled panel"
bind:open
bind:pickerValue={shownPeriod}
onpanelchange={(value, mode) => (moved = describe(value, mode))}
onopenchange={(next) => next && opened++}
/>
<Button onclick={() => (open = true)}>Open the panel</Button>
<span role="status">Opened {opened} times{moved ? `, moved to the ${moved}` : ''}</span>
</div>
<div class="field">
<span class="caption">showWeek and placement="bottomRight"</span>
<DatePicker aria-label="With week numbers" showWeek placement="bottomRight" />
</div>
<div class="field">
<span class="caption">mode="year": the panel stays on the years</span>
<DatePicker aria-label="Years only panel" mode="year" />
</div>
<div class="field">
<span class="caption">container: the panel is drawn inside the box</span>
<div class="box" bind:this={box}>
<DatePicker 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(280px, 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>
locale={ru}
2 декабря 2026
locale={zh}
<script lang="ts">
import { DatePicker, DateRangePicker } from 'svelte-ant-design';
import ru from 'svelte-ant-design/locales/ru';
import zh from 'svelte-ant-design/locales/zh-cn';
const today = new Date();
</script>
<div class="stack">
<div class="field" lang="ru">
<span class="caption">{'locale={ru}'}</span>
<DatePicker aria-label="Дата" locale={ru} format="D MMMM YYYY" value={today} />
<DateRangePicker aria-label="Период" locale={ru} />
</div>
<div class="field" lang="zh-CN">
<span class="caption">{'locale={zh}'}</span>
<DatePicker aria-label="日期" locale={zh} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 6px;
width: min(340px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { DatePicker } 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">
<DatePicker
aria-label="Watched date"
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(280px, 100%);
}
.log {
min-height: 5.5em;
margin: 0;
padding-inline-start: 18px;
}
</style>
Check-in
<script lang="ts">
import { Button, DatePicker, Select, SpaceCompact } from 'svelte-ant-design';
let kind = $state('Check-in');
</script>
<div class="stack">
<div class="field">
<SpaceCompact block>
<Select aria-label="Kind of date" bind:value={kind} options={['Check-in', 'Check-out']} style="width: 150px" />
<DatePicker aria-label="Date of the visit" />
<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 { DatePicker } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">classNames and styles</span>
<DatePicker
aria-label="Styled date"
class="rounded"
style="max-width: 240px"
classNames={{ popup: 'soft', input: 'strong' }}
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(280px, 100%);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
:global(.rounded .strong) {
font-weight: 600;
}
:global(.soft .ads-picker-header) {
background: rgba(22, 119, 255, 0.08);
}
</style>
API
| Property | Description | Type | Default |
|---|---|---|---|
| value | The chosen date; with multiple the list of dates. Bind it with bind:value. | Date | null; Date[] | — |
| picker | What is chosen. A week, month, quarter or year is given as its first day. | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'date' |
| multiple | Several dates, each a tag in the field; the types of value, onchange and onok follow it. Not with showTime. | boolean | false |
| format | How the value is written in the field; with a list the first writes and each reads. By default YYYY-MM-DD, week gggg-wo, YYYY-MM, YYYY-[Q]Q, YYYY. | string | string[] | (date: Date) => string | — |
| showTime | A time next to the date (picker="date" only). | boolean | TimeOptions | false |
| disabledDate | Dates that cannot be chosen; type says what the cell stands for. | (date: Date, info: { type }) => boolean | — |
| disabledTime | Hours, minutes and seconds that cannot be chosen for the date given. | (date: Date | null) => DisabledTimes | — |
| minDate | The first date that can be chosen; the panel does not go before it. | Date | — |
| maxDate | The last date that can be chosen. | Date | — |
| needConfirm | The value changes on OK only; on by default with showTime. | boolean | — |
| showNow | The "Today" button of a date picker, "Now" with a time. | boolean | true |
| showWeek | A column of week numbers (always with picker="week"). | boolean | false |
| presets | Quick choices beside the panel. | { label: string | Snippet; value: Date | (() => Date) }[] | [] |
| mode | The panel that is shown; the parent holds it. | 'date' | 'month' | 'quarter' | 'year' | 'decade' | — |
| pickerValue | The period the panel shows. Bind it with bind:pickerValue. | Date | — |
| 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 calendar icon; null hides it. | string | Snippet | null | — |
| prevIcon | The arrow to the previous month. | Snippet | — |
| nextIcon | The arrow to the next month. | Snippet | — |
| superPrevIcon | The arrow a year (or a decade) back. | Snippet | — |
| superNextIcon | The arrow a year (or a decade) forward. | Snippet | — |
| cellRender | The content of a cell: { date, type, today, selected, inView, text }. | Snippet<[cell: DateCell]> | — |
| extraFooter | Under the panel; a snippet is told which panel is shown. | string | Snippet<[mode]> | — |
| tagRender | A tag of multiple: { value, label, closable, onclose }. | Snippet<[tag: DatePickerTag]> | — |
| maxTagCount | multiple: show this many tags, the rest collapse; responsive keeps one row with as many as fit. | number | 'responsive' | — |
| maxTagPlaceholder | The content of the collapsed tag. | string | Snippet<[omitted: Date[]]> | — |
| order | multiple: the dates are kept in order. | boolean | true |
| 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 | Names, texts and the first day of the week: import ru from 'svelte-ant-design/locales/ru'. | DatePickerLocale | en |
| onchange | The user changed the value; the second argument is the text. | (value, text) => void | — |
| onopenchange | The panel opened or closed. | (open: boolean) => void | — |
| onpanelchange | The panel moved to another period or another panel. | (value: Date, mode) => void | — |
| onok | A value was confirmed with OK or Enter, with needConfirm. | (value) => 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, header, body, cell and footer. | DatePickerClassNames | — |
| styles | Inline styles of the same parts. | DatePickerStyles | — |
| 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; RangePicker is DateRangePicker; languages are objects from svelte-ant-design/locales; the keyboard follows the ARIA date picker pattern. Not in this version: a masked format, previewValue, panelRender, footer buttons of your own and another date library.DateRangePicker
DateRangePicker takes the props of DatePicker without multiple, tagRender, maxTagCount and maxTagPlaceholder; 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: 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 |
| disabledDate | Dates that cannot be chosen; from is the other end once it is chosen. | (date, info: { type, from? }) => boolean | — |
| 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; 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> | — |
TimeOptions
| Property | Description | Type | Default |
|---|---|---|---|
| format | The pattern of the time; it decides which columns exist. With use12Hours the default is hh:mm:ss a; without seconds the seconds are left out. | string | 'HH:mm:ss' |
| hourStep | Every n-th hour. | number | 1 |
| minuteStep | Every n-th minute. | number | 1 |
| secondStep | Every n-th second. | number | 1 |
| use12Hours | Hours from 1 to 12 with AM or PM. | boolean | false |
| showSecond | false removes the seconds. | boolean | true |
| defaultOpenValue | The time (and the day) a choice starts from. | Date | — |
| hideDisabledOptions | Disabled numbers are not shown. | boolean | false |
DatePickerLocale
| Property | Description | Type | Default |
|---|---|---|---|
| calendar | Names of months and days and the week rule, in the shape of a dayjs locale; without it English. | CalendarData | — |
| texts | The texts of the component: placeholders, names of buttons and of the panel, "Today", "OK", and the words said after a date of several is chosen or removed (announce, English if missing). | DatePickerTexts | — |
| patterns | How the panels write months, years, weekdays and days. | DatePickerPatterns | — |
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-picker-panel-width | Width of one calendar. | 288px |
| --ads-picker-header-height | Height of the head of a panel. | 40px |
| --ads-picker-cell-height | Height of a cell of days. | 36px |
| --ads-picker-cell-mark | Height of the mark of a cell. | 24px |
| --ads-picker-period-height | Height of a cell of months, quarters and years. | 66px |
| --ads-picker-actions-height | Least height of the buttons under the panel. | 42px |
| --ads-picker-presets-width | Width of the column of quick choices. | 120px |
| --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-icon-color | The icons of the field and of the head. | rgba(0, 0, 0, 0.45) |
| --ads-picker-week-color | The week numbers. | var(--ads-color-text-disabled) |
| --ads-picker-outside-color | The days of the neighboring months. | var(--ads-color-text-disabled) |
| --ads-picker-cell-hover-bg | A cell under the pointer. | rgba(0, 0, 0, 0.04) |
| --ads-picker-disabled-bg | A cell that cannot be chosen. | rgba(0, 0, 0, 0.04) |
| --ads-picker-today-border | The border of today and of a day of a range under the pointer. | var(--ads-color-primary) |
| --ads-picker-selected-bg | The chosen date. | var(--ads-color-primary-solid) |
| --ads-picker-selected-color | The text of the chosen date. | #ffffff |
| --ads-picker-time-column-width | Width of a column of a time. | 56px |
| --ads-picker-time-column-height | Height of the columns of a time. | 262px |
| --ads-picker-time-item-height | Height of a number of a time. | 28px |
| --ads-picker-time-selected-bg | The chosen number of a time. | #e6f4ff |
| --ads-picker-range-bg | The days between the ends of a range. | #e6f4ff |
| --ads-picker-range-hover-bg | The range that a choice under the pointer would give. | #f0f8ff |
Keyboard
Arrow Downin the field opens the panel and moves the focus into the calendar.- In the calendar the arrows move by a day and a week,
HomeandEndto the ends of the week,Page UpandPage Downby a month, withShiftby a year. EnterorSpacechooses. In a range the focus then goes to the input of the other end, and after the second end back to the input.Escapecloses the panel 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 header buttons, the calendar (one stop) and the footer.- In the columns of a time
UpandDownchange the number,LeftandRightthe column,Entertakes it.
Accessibility
- The field is a
comboboxthat names its dialog; the calendar is a grid named by the month, with every day named by the full date and today marked as current. A change of the shown month is announced once. - 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 marks of today, the chosen dates and a range stay visible in forced colors. - Checked with a real screen reader (Orca with Firefox): it reads the field with its value, the name of the dialog, the dates of the calendar with their state, the month, the dates chosen and removed among several, the ends of a range and the columns of a time. Orca does not say the value of such a field by itself, so every input gives it as its description: NVDA, JAWS and VoiceOver, not checked, may say it twice. Not checked with NVDA, JAWS, VoiceOver or on a phone.