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.

Import
import { DatePicker, DateRangePicker } from 'svelte-ant-design';
Links
src/lib/DatePicker Report an issue Component README

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 DateRangePicker for two dates that belong together, not two separate pickers.

Examples

Chosen: nothing

Basic

A press opens the panel; the value is a Date. A date can also be typed.

picker="week"
picker="month"
picker="quarter"
picker="year"

Week, month, quarter, year

picker chooses what is picked. The value is the first day of the week, month, quarter or year.

format="DD.MM.YYYY"
format as a list: the first writes, each one reads
format as a function

Format

format writes and reads the text of the field: a pattern, a list of patterns or a function (then the field reads nothing typed).

showTime: the value waits for OK
Value: nothing
12 hours, steps of 15 minutes, no seconds
needConfirm=false, showNow=false
Value: nothing

Date and time

showTime adds columns of hours, minutes and seconds. The value then waits for OK unless needConfirm is off.

disabledDate: working days only
minDate and maxDate: the rest of this month
disabledTime: 9:00 to 17:59

Dates that cannot be chosen

disabledDate, minDate, maxDate and disabledTime take dates and times out of the panel.

needConfirm, onok, extraFooter

Confirm with OK

With needConfirm the value changes on OK only. extraFooter adds text under the panel.

Due: not set

Quick choices

presets stand beside the panel; a value may be computed when it is pressed.

multiple, order=true
2026-01-05 2026-01-07
2 chosen
maxTagCount=2, maxTagPlaceholder
2026-01-05 2026-01-07 and 3 more
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 ...
tagRender

Several dates

multiple keeps each date as a tag; a chosen date pressed again is removed. The tags collapse with maxTagCount.

No stay chosen

Range

DateRangePicker asks for the start and then the end, and calls onchange once, when both are chosen.

picker="month"
showTime: each end waits for OK
presets

Ranges of months, with time, with presets

A range takes the same picker, showTime and presets.

allowEmpty: the end may stay empty
disabled={[true, false]}: the start is fixed
disabledDate with from: seven days at most
order=false, separator, id

The ends of a range

Either end may stay empty or be fixed; disabledDate is told the other end; without order the end may be earlier than the start.

disabled
inputReadOnly: no typing, no keyboard on a phone
allowClear=false
allowClear with an icon and a name

Disabled, read-only, clear

inputReadOnly keeps typing and the phone keyboard away. allowClear hides or changes the clear button.

size="large"
size="medium"
size="small"

Sizes

large, medium and small: 40, 32 and 24px, as the other fields.

variant="outlined"
variant="filled"
variant="borderless"
variant="underlined"

Variants

outlined, filled, borderless and underlined.

status="error"
Choose your birthday.
status="warning"
These days are almost fully booked.

Status

status paints an error or a warning; say what is wrong in text next to the field.

prefix and suffix
From ✈
suffix=null: no icon
prevIcon, nextIcon, superPrevIcon, superNextIcon

Icons

prefix and suffix in the field, and the arrows of the head.

cellRender: the paydays are underlined

Own cells

cellRender draws the content of every cell; the button of the cell and its name stay.

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

The panel

open, pickerValue and mode hold the panel; showWeek, placement and container change where and how it is drawn.

locale={ru}
locale={zh}

Language

locale brings the names of months and days, the first day of the week and the texts. English is built in; Russian and Chinese ship with the library.

Callbacks

onchange and onclear; onfocus and onblur fire once for the field and its panel together.

In a compact block

In a SpaceCompact the field joins the controls beside it.

classNames and styles

Classes and styles

classNames and styles address the parts of the field and of the panel.

API

PropertyDescriptionTypeDefault
valueThe chosen date; with multiple the list of dates. Bind it with bind:value.Date | null; Date[]—
pickerWhat is chosen. A week, month, quarter or year is given as its first day.'date' | 'week' | 'month' | 'quarter' | 'year''date'
multipleSeveral dates, each a tag in the field; the types of value, onchange and onok follow it. Not with showTime.booleanfalse
formatHow 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—
showTimeA time next to the date (picker="date" only).boolean | TimeOptionsfalse
disabledDateDates that cannot be chosen; type says what the cell stands for.(date: Date, info: { type }) => boolean—
disabledTimeHours, minutes and seconds that cannot be chosen for the date given.(date: Date | null) => DisabledTimes—
minDateThe first date that can be chosen; the panel does not go before it.Date—
maxDateThe last date that can be chosen.Date—
needConfirmThe value changes on OK only; on by default with showTime.boolean—
showNowThe "Today" button of a date picker, "Now" with a time.booleantrue
showWeekA column of week numbers (always with picker="week").booleanfalse
presetsQuick choices beside the panel.{ label: string | Snippet; value: Date | (() => Date) }[][]
modeThe panel that is shown; the parent holds it.'date' | 'month' | 'quarter' | 'year' | 'decade'—
pickerValueThe period the panel shows. Bind it with bind:pickerValue.Date—
placeholderThe hint of the empty field; by default from the locale.string—
disabledThe field cannot be used.booleanfalse
inputReadOnlyThe field cannot be typed in; a phone shows no keyboard.booleanfalse
allowClearA button that empties the value; an object changes its icon, name and tabindex.boolean | { clearIcon?, label?, tabIndex? }true
sizemedium unless a SpaceCompact says otherwise; middle and default are aliases.'large' | 'medium' | 'middle' | 'small' | 'default'—
variantThe look of the field.'outlined' | 'filled' | 'borderless' | 'underlined''outlined'
statusPaints an error or a warning; error also sets aria-invalid.'error' | 'warning'—
prefixBefore the text.string | Snippet—
suffixReplaces the calendar icon; null hides it.string | Snippet | null—
prevIconThe arrow to the previous month.Snippet—
nextIconThe arrow to the next month.Snippet—
superPrevIconThe arrow a year (or a decade) back.Snippet—
superNextIconThe arrow a year (or a decade) forward.Snippet—
cellRenderThe content of a cell: { date, type, today, selected, inView, text }.Snippet<[cell: DateCell]>—
extraFooterUnder the panel; a snippet is told which panel is shown.string | Snippet<[mode]>—
tagRenderA tag of multiple: { value, label, closable, onclose }.Snippet<[tag: DatePickerTag]>—
maxTagCountmultiple: show this many tags, the rest collapse; responsive keeps one row with as many as fit.number | 'responsive'—
maxTagPlaceholderThe content of the collapsed tag.string | Snippet<[omitted: Date[]]>—
ordermultiple: the dates are kept in order.booleantrue
openWhether the panel is shown. Bind it with bind:open.booleanfalse
placementThe side the panel prefers; it flips at the edge of the screen.'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight''bottomLeft'
containerWhere the panel is put (default: the end of <body>).HTMLElement | (anchor) => HTMLElement—
localeNames, texts and the first day of the week: import ru from 'svelte-ant-design/locales/ru'.DatePickerLocaleen
onchangeThe user changed the value; the second argument is the text.(value, text) => void—
onopenchangeThe panel opened or closed.(open: boolean) => void—
onpanelchangeThe panel moved to another period or another panel.(value: Date, mode) => void—
onokA value was confirmed with OK or Enter, with needConfirm.(value) => void—
onclearThe clear button emptied the value.() => void—
onfocusThe focus came to the field or its panel from outside.(event: FocusEvent) => void—
onblurThe focus left both.(event: FocusEvent) => void—
classNamesExtra classes of root, input, prefix, suffix, popup, header, body, cell and footer.DatePickerClassNames—
stylesInline styles of the same parts.DatePickerStyles—
class / styleClass and style of the field.string—
native attributesThe 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.

PropertyDescriptionTypeDefault
valueThe start and the end; an end not chosen is null. Bind it with bind:value.[Date | null, Date | null] | nullnull
placeholderThe hints of the two inputs; by default from the locale.[string, string]—
inputLabelsThe accessible names of the two inputs; by default from the locale.[string, string]—
disabledBoth ends, or each. A disabled end keeps its value and fixes the order.boolean | [boolean, boolean]false
allowEmptyAn end that may stay empty.[boolean, boolean][false, false]
separatorBetween the inputs; an arrow by default.string | Snippet—
orderThe start is not after the end: two ends chosen now swap, an end kept from before is asked again.booleantrue
idThe ids of the two inputs.{ start?: string; end?: string }—
autofocusThe start input takes the focus when the page loads.booleanfalse
disabledDateDates that cannot be chosen; from is the other end once it is chosen.(date, info: { type, from? }) => boolean—
disabledTimeTimes that cannot be chosen, for the end asked.(date: Date | null, range: 'start' | 'end') => DisabledTimes—
presetsQuick choices that give both ends.{ label; value: [Date, Date] | (() => [Date, Date]) }[][]
onchangeThe range changed: once, when it is complete.(value, text: [string, string]) => void—
oncalendarchangeAn end was chosen; range says which.(value, text, info: { range }) => void—
onokA range was confirmed with OK or Enter, with needConfirm.(value) => void—
onfocusThe focus came to the field or its panel from outside.(event, info: { range }) => void—
onblurThe focus left both.(event, info: { range }) => void—
native attributesThe other attributes go to the root, a group: aria-label, data-*.HTMLAttributes<HTMLDivElement>—

TimeOptions

PropertyDescriptionTypeDefault
formatThe 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'
hourStepEvery n-th hour.number1
minuteStepEvery n-th minute.number1
secondStepEvery n-th second.number1
use12HoursHours from 1 to 12 with AM or PM.booleanfalse
showSecondfalse removes the seconds.booleantrue
defaultOpenValueThe time (and the day) a choice starts from.Date—
hideDisabledOptionsDisabled numbers are not shown.booleanfalse

DatePickerLocale

PropertyDescriptionTypeDefault
calendarNames of months and days and the week rule, in the shape of a dayjs locale; without it English.CalendarData—
textsThe 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—
patternsHow the panels write months, years, weekdays and days.DatePickerPatterns—

Methods

MethodDescriptionType
focusMoves focus to the field; in a range, to the end that is asked. The panel does not open.(options?: FocusOptions) => void
blurRemoves focus from the field; the panel closes.() => void

Design tokens

TokenDescriptionDefault
--ads-picker-panel-widthWidth of one calendar.288px
--ads-picker-header-heightHeight of the head of a panel.40px
--ads-picker-cell-heightHeight of a cell of days.36px
--ads-picker-cell-markHeight of the mark of a cell.24px
--ads-picker-period-heightHeight of a cell of months, quarters and years.66px
--ads-picker-actions-heightLeast height of the buttons under the panel.42px
--ads-picker-presets-widthWidth of the column of quick choices.120px
--ads-picker-popup-radiusCorner radius of the panel.8px
--ads-picker-popup-bgBackground of the panel.#ffffff
--ads-picker-popup-shadowShadow 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-colorThe icons of the field and of the head.rgba(0, 0, 0, 0.45)
--ads-picker-week-colorThe week numbers.var(--ads-color-text-disabled)
--ads-picker-outside-colorThe days of the neighboring months.var(--ads-color-text-disabled)
--ads-picker-cell-hover-bgA cell under the pointer.rgba(0, 0, 0, 0.04)
--ads-picker-disabled-bgA cell that cannot be chosen.rgba(0, 0, 0, 0.04)
--ads-picker-today-borderThe border of today and of a day of a range under the pointer.var(--ads-color-primary)
--ads-picker-selected-bgThe chosen date.var(--ads-color-primary-solid)
--ads-picker-selected-colorThe text of the chosen date.#ffffff
--ads-picker-time-column-widthWidth of a column of a time.56px
--ads-picker-time-column-heightHeight of the columns of a time.262px
--ads-picker-time-item-heightHeight of a number of a time.28px
--ads-picker-time-selected-bgThe chosen number of a time.#e6f4ff
--ads-picker-range-bgThe days between the ends of a range.#e6f4ff
--ads-picker-range-hover-bgThe range that a choice under the pointer would give.#f0f8ff

Keyboard

  • Arrow Down in the field opens the panel and moves the focus into the calendar.
  • In the calendar the arrows move by a day and a week, Home and End to the ends of the week, Page Up and Page Down by a month, with Shift by a year.
  • Enter or Space chooses. In a range the focus then goes to the input of the other end, and after the second end back to the input.
  • Escape closes the panel and returns the focus to the field.
  • Tab leaves 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 Up and Down change the number, Left and Right the column, Enter takes it.

Accessibility

  • The field is a combobox that 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 group with two named inputs; the dialog says which end it asks for. Give the group a name with aria-label.
  • The default light colors follow Ant Design and not all reach a contrast of 4.5:1; load tokens-accessible.css for 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.