Skip to content
Likable Aurora @likable-hair/svelte 5

DatePickerTextField

Date field: type the date or choose it in a calendar. The value is selectedDate, a Date at local midnight; with range the field has a start and an end input and selectedDateTo holds the end. The format comes from locale (en is MM/dd/yyyy, it dd/MM/yyyy) or from format, and it is shown as a chip after the text, which hides itself when the field is too narrow for both. Typing accepts digits only and adds the separators; a whole date that does not exist, is outside min and max or is disabled by isDateDisabled (and an unfinished one when the field loses focus) turns the field to the error state with invalidText, and the form refuses to submit it. On desktop, focusing or clicking the field opens a DatePicker in a menu; Arrow Down moves the focus into it, Escape closes it and Tab leaves it. On screens up to 1024px wide the calendar button opens it in a bottom drawer instead, and the field stays typable with the numeric keyboard (mobileDrawer). Choosing a day closes the calendar (closeOnSelect). months={2} shows two months side by side in the menu. With confirm the calendar works on a draft that only the Apply button at its bottom saves; Cancel, Escape and a click outside discard it. With name (and nameTo) the value is submitted as yyyy-MM-dd. Its state is exposed as data-state, data-disabled, data-readonly, data-open and data-range for app CSS.

import { DatePickerTextField } from '@likable-hair/svelte';

src/lib/components/composed/forms/DatePickerTextField.svelte ยท Markdown for LLMs

Type or choose

Type the digits (the separators come by themselves) or open the calendar: focus the field, then Arrow Down moves into the calendar and Escape closes it. Choosing a day closes it. On a phone the calendar button opens a bottom drawer instead.

Value: 2026-09-24

Code
<script lang="ts">
	import { DatePickerTextField, toISODate } from '@likable-hair/svelte';

	let selectedDate = $state<Date | undefined>(new Date(2026, 8, 24));
</script>

<div class="example">
	<DatePickerTextField label="Appointment date" bind:selectedDate />
	<p>Value: {selectedDate ? toISODate(selectedDate) : 'none'}</p>
</div>

<style>
	.example {
		display: grid;
		gap: 12px;
		width: 340px;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>

Range

With range the field has a start and an end input, and the calendar picks the start with the first click and the end with the second, then closes.

Code
<script lang="ts">
	import { DatePickerTextField } from '@likable-hair/svelte';

	let selectedDate = $state<Date | undefined>(new Date(2026, 8, 11));
	let selectedDateTo = $state<Date | undefined>(new Date(2026, 8, 24));
</script>

<div class="example">
	<DatePickerTextField
		label="Report period"
		locale="en-GB"
		range
		clearable
		bind:selectedDate
		bind:selectedDateTo
	/>
</div>

<style>
	.example {
		width: 380px;
	}
</style>

Limits and forms

min, max and isDateDisabled limit the calendar and the typed date: an invalid or unfinished date shows invalidText and the form refuses it. With name the date is submitted as yyyy-MM-dd.

September to December, closed on Sundays
Required for the loyalty card

Nothing submitted yet

Code
<script lang="ts">
	import { Button, DatePickerTextField } from '@likable-hair/svelte';

	let submitted = $state('');

	function submit(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
		event.preventDefault();
		submitted = new URLSearchParams(new FormData(event.currentTarget) as never).toString();
	}
</script>

<form onsubmit={submit}>
	<DatePickerTextField
		label="Booking"
		name="booking"
		locale="en-GB"
		required
		clearable
		min={new Date(2026, 8, 1)}
		max={new Date(2026, 11, 31)}
		isDateDisabled={(date) => date.getDay() === 0}
		hint="September to December, closed on Sundays"
	/>
	<DatePickerTextField label="Birth date" locale="en-GB" state="error" hint="Required for the loyalty card" />
	<Button type="submit">Book</Button>
	<p>{submitted ? `Submitted: ${submitted}` : 'Nothing submitted yet'}</p>
</form>

<style>
	form {
		display: grid;
		justify-items: start;
		gap: 14px;
		width: 340px;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>

Locale and format

locale sets the format, the names in the calendar, the first day of the week and the texts: with it the chip reads gg/mm/aaaa and the buttons and the error are in Italian (setDefaultLocale('it') in the root layout does it for the whole app). Text props such as invalidText win over it. format sets any order and separator with dd, MM and yyyy.

Code
<script lang="ts">
	import { DatePickerTextField } from '@likable-hair/svelte';

	let italian = $state<Date | undefined>(new Date(2026, 8, 24));
	let iso = $state<Date | undefined>(new Date(2026, 8, 24));
</script>

<div class="example">
	<DatePickerTextField
		label="Data appuntamento"
		locale="it"
		invalidText="Data non valida"
		bind:selectedDate={italian}
	/>
	<DatePickerTextField label="ISO format" format="yyyy-MM-dd" bind:selectedDate={iso} />
</div>

<style>
	.example {
		display: grid;
		gap: 14px;
		width: 340px;
	}
</style>

Two months and Apply

months={2} shows two months side by side in the menu (one in the mobile drawer). With confirm the clicks only change a draft: Apply saves it and calls onchange, Cancel, Escape or a click outside discard it, and with clearable Clear empties the field. Useful when every change starts a new search.

Searches run: 0

Code
<script lang="ts">
	import { DatePickerTextField } from '@likable-hair/svelte';

	let selectedDate = $state<Date | undefined>(new Date(2026, 8, 7));
	let selectedDateTo = $state<Date | undefined>(new Date(2026, 9, 2));
	let searches = $state(0);
</script>

<div class="example">
	<DatePickerTextField
		label="Invoices issued"
		locale="en-GB"
		range
		months={2}
		confirm
		clearable
		bind:selectedDate
		bind:selectedDateTo
		onchange={() => searches++}
	/>
	<p>Searches run: {searches}</p>
</div>

<style>
	.example {
		display: grid;
		gap: 12px;
		width: 380px;
	}

	p {
		margin: 0;
		font-size: 14px;
	}
</style>

Props

NameTypeDefaultDescription
selectedDate bindable DateThe date, at local midnight; with range, the start of the range. undefined while the field is empty or its text is not a valid date.
selectedDateTo bindable DateWith range, the end of the range.
range booleanfalseChooses a range: the field has a start and an end input, and the calendar picks the start with the first click and the end with the second.
open bindable booleanWhether the calendar is open. undefined counts as closed.
locale stringBCP 47 locale of the format, of the names in the calendar, of the first day of the week and of the texts (it and en are built in, other languages fall back to English). Defaults to the one set with setDefaultLocale, else en.
format stringFormat of the typed date, with the tokens dd, MM and yyyy and any separator (dd/MM/yyyy, yyyy-MM-dd, dd.MM.yyyy). Defaults to the one of locale.
weekStart 0 | 1 | 2 | 3 | 4 | 5 | 6First day of the week in the calendar, from 0 (Sunday) to 6 (Saturday). Defaults to the one of locale.
weekdayFormat 'narrow' | 'short' | 'long''short'Length of the names of the days of the week in the calendar.
showOutsideDays booleantrueShows in the calendar the days of the previous and next month that complete the first and last week.
min DateEarliest date that can be chosen or typed. It also limits the months and years of the calendar.
max DateLatest date that can be chosen or typed.
isDateDisabled (date: Date) => booleanReturns true for the days that cannot be chosen or typed (weekends, holidays, ...).
label stringVisible label above the field, linked to the input. In the mobile drawer it is the title.
hint stringText below the field. With state it becomes the error or success message.
state 'error' | 'success'Validation state: colors the border and the hint and shows an icon. error also sets aria-invalid. Without it the field still shows the error state for an invalid date.
invalidText stringMessage shown below the field, and given to the form, when the typed date is not valid. Defaults to "Enter a valid date", in the language of locale.
placeholder stringPlaceholder of the (start) input. Without it the format chip tells what to type.
placeholderTo stringWith range, placeholder of the end input.
disabled booleanfalseNative disabled: the field and the calendar cannot be used.
readonly booleanfalseNative readonly: the date is shown and can be selected, but not changed.
required booleanfalseNative required on the inputs.
id stringid of the (start) input. Generated when missing, so the label always points to it.
name stringName of a hidden input that submits the date as yyyy-MM-dd (empty when there is no date).
nameTo stringWith range, name of the hidden input with the end date.
clearable booleanfalseShows a button that empties the field.
clearLabel stringAccessible name of the clear button. Defaults to "Clear", in the language of locale.
closeOnSelect booleantrueCloses the calendar when a day is chosen (with range, when the end is chosen). Ignored with confirm.
months 1 | 21Months shown side by side in the calendar menu: 2 helps to pick long ranges. The mobile drawer always shows one.
confirm booleanfalseThe calendar works on a draft: the date (or the range) changes only with the Apply button at its bottom, while Cancel, Escape and a click outside discard the draft. With clearable the bottom also has a Clear button, which empties the field and closes the calendar. Typing in the field still changes the date at once.
applyLabel stringText of the Apply button, with confirm. Defaults to "Apply", in the language of locale.
cancelLabel stringText of the Cancel button, with confirm. Defaults to "Cancel", in the language of locale.
placement 'bottom-start' | 'bottom' | 'bottom-end' | 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end''bottom-start'Side of the field where the calendar menu opens. It flips when there is not enough space.
mobileDrawer booleantrueOn screens up to 1024px wide, opens the calendar in a bottom drawer from the calendar button instead of a menu, and focusing the field does not open it.
drawerTitle stringTitle of the mobile drawer. Defaults to label.
closeLabel stringAccessible name of the close button of the mobile drawer. Defaults to "Close", in the language of locale.
openLabel stringAccessible name of the calendar button, and of the calendar when there is no label. Defaults to "Choose date", in the language of locale.
startLabel stringWith range, accessible name of the start input, after the label. Defaults to "Start date", in the language of locale.
endLabel stringWith range, accessible name of the end input, after the label. Defaults to "End date", in the language of locale.
showFormat booleantrueShows the format as a chip after the text, also read by screen readers. The chip hides itself while the field is too narrow for the whole text and the chip.
formatLabel stringText of the format chip. Defaults to the format in lowercase, with the letters of the language of locale (dd/mm/yyyy, in Italian gg/mm/aaaa).
previousMonthLabel stringAccessible name of the calendar's left arrow in the day view (DatePicker). Defaults to "Previous month", in the language of locale.
nextMonthLabel stringAccessible name of the calendar's right arrow in the day view. Defaults to "Next month", in the language of locale.
previousYearLabel stringAccessible name of the calendar's left arrow in the month view. Defaults to "Previous year", in the language of locale.
nextYearLabel stringAccessible name of the calendar's right arrow in the month view. Defaults to "Next year", in the language of locale.
input bindable HTMLInputElementThe (start) input element.
inputTo bindable HTMLInputElementWith range, the end input element.
class { container?: string; label?: string; row?: string; field?: string; input?: string; hint?: string; picker?: string; }{}Extra classes for each part. picker goes on the DatePicker.

It also accepts the native attributes and events of <input> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
labelSnippet{ label: string | undefined }Replaces the label content. It stays linked to the input.
hintSnippet{ hint: string | undefined }Replaces the hint below the field.
stateIconSnippet{ state: 'error' | 'success' }Replaces the icon shown for the validation state. Render nothing to hide it.
iconSnippetReplaces the calendar icon. The button around it keeps opening the calendar.
prependSnippetContent outside the field, on the left.
appendInnerSnippetContent inside the field, after the format chip and before the clear button.
appendSnippetContent outside the field, on the right.
clearSnippetReplaces the icon of the clear button.
formatSnippet{ format: string }Replaces the content of the format chip.
daySnippetCalendarDayReplaces the number of a day in the calendar (see Calendar).
dayAppendSnippetCalendarDayContent after the number of a day in the calendar (see Calendar).

Events

NameTypeDescription
onchange(event: { selectedDate: Date | undefined; selectedDateTo: Date | undefined }) => voidCalled when the user changes the date: in the calendar, by typing a whole valid date (or making it invalid again) and with the clear button.

Types

Exported by the package: import type { CalendarDay } from '@likable-hair/svelte';

CalendarDay

A day of the grid, as the day snippets receive it.

interface CalendarDay

NameTypeDescription
date requiredDateThe day, at local midnight.
outside requiredbooleanThe day belongs to the month before or after the visible one.
selected requiredbooleanThe day is the chosen one, or an end of the chosen range.
inRange requiredbooleanThe day is inside the chosen range, ends excluded.
today requiredbooleanThe day is today.
disabled requiredbooleanThe day cannot be chosen (min, max, isDateDisabled).

CSS variables

For a single instance, pass them as style props: <DatePickerTextField --date-picker-text-field-background="tomato">. The --date-picker-text-field-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--date-picker-text-field-border-color
--date-picker-text-field-default-border-color var(--global-input-border-color)
--date-picker-text-field-hover-border-color
--date-picker-text-field-default-hover-border-color var(--global-input-hover-border-color)
--date-picker-text-field-focus-border-color
--date-picker-text-field-default-focus-border-color var(--global-input-focus-border-color)
--date-picker-text-field-focus-ring-color
--date-picker-text-field-default-focus-ring-color var(--global-input-focus-ring-color)
--date-picker-text-field-hint-color
--date-picker-text-field-default-hint-color var(--global-input-hint-color)
--date-picker-text-field-icon-size
--date-picker-text-field-default-icon-size 18px
--date-picker-text-field-gap
--date-picker-text-field-default-gap 6px
--date-picker-text-field-width
--date-picker-text-field-default-width 100%
--date-picker-text-field-max-width
--date-picker-text-field-default-max-width none
--date-picker-text-field-error-color
--date-picker-text-field-default-error-color var(--global-input-error-color)
--date-picker-text-field-success-color
--date-picker-text-field-default-success-color var(--global-input-success-color)
--date-picker-text-field-label-color
--date-picker-text-field-default-label-color var(--global-input-label-color)
--date-picker-text-field-label-font-size
--date-picker-text-field-default-label-font-size var(--global-input-label-font-size)
--date-picker-text-field-label-font-weight
--date-picker-text-field-default-label-font-weight var(--global-input-label-font-weight)
--date-picker-text-field-outer-gap
--date-picker-text-field-default-outer-gap 8px
--date-picker-text-field-icon-color
--date-picker-text-field-default-icon-color var(--global-input-icon-color)
--date-picker-text-field-inner-gap
--date-picker-text-field-default-inner-gap var(--global-input-gap)
--date-picker-text-field-height
--date-picker-text-field-default-height var(--global-input-height)
--date-picker-text-field-padding
--date-picker-text-field-default-padding 0 var(--global-input-padding-x)
--date-picker-text-field-background
--date-picker-text-field-default-background var(--global-input-background)
--date-picker-text-field-border-width
--date-picker-text-field-default-border-width var(--global-input-border-width)
--date-picker-text-field-border-radius
--date-picker-text-field-default-border-radius var(--global-input-radius)
--date-picker-text-field-box-shadow
--date-picker-text-field-default-box-shadow var(--global-input-shadow)
--date-picker-text-field-focus-ring-width
--date-picker-text-field-default-focus-ring-width var(--global-focus-ring-width)
--date-picker-text-field-color
--date-picker-text-field-default-color var(--global-input-color)
--date-picker-text-field-font-family
--date-picker-text-field-default-font-family var(--global-font-family-mono)
--date-picker-text-field-font-size
--date-picker-text-field-default-font-size var(--global-input-font-size)
--date-picker-text-field-font-weight
--date-picker-text-field-default-font-weight 400
--date-picker-text-field-placeholder-color
--date-picker-text-field-default-placeholder-color var(--global-input-placeholder-color)
--date-picker-text-field-separator-color
--date-picker-text-field-default-separator-color var(--global-color-text-3)
--date-picker-text-field-format-padding
--date-picker-text-field-default-format-padding 2px 6px
--date-picker-text-field-format-border-color
--date-picker-text-field-default-format-border-color var(--global-color-border)
--date-picker-text-field-format-border-radius
--date-picker-text-field-default-format-border-radius var(--global-radius-xs)
--date-picker-text-field-format-background
--date-picker-text-field-default-format-background var(--global-color-surface-2)
--date-picker-text-field-format-color
--date-picker-text-field-default-format-color var(--global-color-text-3)
--date-picker-text-field-format-font-size
--date-picker-text-field-default-format-font-size 11px
--date-picker-text-field-hint-font-size
--date-picker-text-field-default-hint-font-size var(--global-input-hint-font-size)
--date-picker-text-field-disabled-background
--date-picker-text-field-default-disabled-background var(--global-input-disabled-background)
--date-picker-text-field-disabled-opacity
--date-picker-text-field-default-disabled-opacity var(--global-input-disabled-opacity)