Skip to content

Components

Date pickers

DatePicker and DateRangePicker share one calendar, keyboard model and set of snippets. Values are YYYY-MM-DD strings, so a selection cannot shift by a day across timezones.

Live demo

This is the Tailwind wrapper from the recipe below, running. Pick a range and watch the bound value change.

Bound value: 2026-10-05 to 2026-10-08

Usage

A range is { start, end }. Every snippet is optional, and the trigger snippet receives the formatted label and a clear function.

<script>
	import { DateRangePicker, addDays, today } from '@frostycle/rime/date-picker';

	let period = $state(null);

	const presets = [
		{ label: 'Today', value: () => ({ start: today(), end: today() }) },
		{ label: 'Last 7 days', value: () => ({ start: addDays(today(), -6), end: today() }) }
	];
</script>

<DateRangePicker
	bind:value={period}
	months={2}
	{presets}
	locale="id-ID"
	startName="from"
	endName="to"
	classes={{ popup: 'rounded-lg border bg-white p-4', day: 'size-9 data-[selected]:bg-blue-600' }}
>
	{#snippet trigger({ props, label, clear, value })}
		<button {...props}>{label || 'Choose dates'}</button>
		{#if value}<button type="button" onclick={clear}>Clear</button>{/if}
	{/snippet}
</DateRangePicker>

DatePicker takes a single string. With name it renders a hidden input, so it submits with a form.

<form method="GET">
	<DatePicker bind:value={due} name="due" min={today()} />
</form>

Props

PropTypeApplies toNotes
valuestring | null, or { start, end } | nullbothBindable. Malformed values and reversed ranges throw.
onchange(value) => voidbothFires on user commits and clear, not when the parent sets value.
minstringbothInclusive.
maxstringbothInclusive.
isDateDisabled(date: string) => booleanbothA range may span disabled dates; only its endpoints are checked.
minDaysnumberrangeLength counting both endpoints.
maxDaysnumberrangeLength counting both endpoints.
monthsnumberboth Default 1.
presets{ label, value: () => V }[]bothCommit on click. Disabled when the result breaks the constraints.
localestringboth Default en-US.
weekStartsOn0 to 6both Default from the locale, otherwise Sunday.
labels{ previousMonth, nextMonth, dialog, inRange }bothAccessible names. dialog also labels the default trigger when empty; inRange is appended to the name of days inside a range.
disabledbooleanbothRenders no hidden inputs.
transitionbooleanbothKeeps the popup mounted through its CSS transition. Default false.
namestringsingleRenders a hidden input.
startNamestringrangeRenders two hidden inputs with endName, for ?from=…&to=… filter forms.
endNamestringrangeRenders two hidden inputs with startName, for ?from=…&to=… filter forms.
classes{ trigger, popup, body, month, header, title, nav, grid, weekday, cell, day, presets, preset }bothClasses for default-rendered elements.

Snippets

All optional. Spread each props onto your element.

  • trigger

    props, label, value, open, clear

  • popup

    props, content

    Render content for the default body.

  • header

    title, titleProps, previousProps, nextProps

    Rendered per month. previousProps is null except on the first month, nextProps except on the last.

  • grid

    month, weekdays, weeks, props, renderDay

    Rendered per month. weeks holds null outside that month. Call {@render renderDay(date)} for each date.

  • day

    date, dayNumber, props, selected, inRange, rangeStart, rangeEnd, preview, isToday, disabled

    Spread props onto a <button>: Enter and Space rely on its native click.

  • presetList

    presets, select

    Each preset carries disabled.

Keyboard

Left, Right
Previous or next day. Reversed in right-to-left layouts
Up, Down
Same weekday in the previous or next week
Home, End
First or last day of the week
PageUp, PageDown
Same date in the previous or next month
Shift + PageUp, PageDown
Same date in the previous or next year
Enter, Space
Pick the focused day
Escape
Close and return focus to the trigger
Tab
Move through the popup. Moving focus out of it closes it

State attributes

Style state with data-* attributes rather than props. They are present or absent, with no value. data-focus appears for keyboard focus only, and data-hover ignores touch. Disabled elements take neither data-hover nor data-active.

ElementAttributes
Triggerdata-open, data-disabled, data-hover, data-focus, data-active
Popupdata-open, plus data-closed, data-enter and data-leave with transition
Daydata-selected, data-in-range, data-range-start, data-range-end, data-preview, data-today, data-disabled, data-hover, data-focus, data-active
Previous, next, default presetsdata-hover, data-focus, data-active

Tailwind recipe

The library ships no Tailwind classes, so there is nothing to configure or override. Copy this wrapper into your project and own it. It needs Tailwind CSS v4, whose bare data-selected: variants it uses; in v3 write data-[selected]:.

import type { PickerClasses } from '@frostycle/rime/date-picker';

export const pickerClasses: PickerClasses = {
	trigger:
		'rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 data-hover:bg-gray-50 data-focus:outline-2 data-focus:outline-offset-2 data-focus:outline-blue-600 data-open:border-blue-600 data-disabled:opacity-50 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 dark:data-hover:bg-gray-700',
	popup:
		'rounded-lg border border-gray-200 bg-white p-4 text-gray-900 shadow-lg transition duration-150 ease-out data-closed:-translate-y-1 data-closed:opacity-0 motion-reduce:transition-none dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100',
	body: 'flex flex-wrap gap-6',
	presets: 'flex flex-col gap-1',
	preset:
		'rounded-md px-2 py-1 text-start text-sm data-hover:bg-gray-100 data-focus:outline-2 data-focus:outline-blue-600 disabled:opacity-40 dark:data-hover:bg-gray-700',
	header: 'mb-2 flex items-center gap-2',
	title: 'flex-1 text-center text-sm font-semibold',
	nav: 'size-8 rounded-md data-hover:bg-gray-100 data-focus:outline-2 data-focus:outline-blue-600 dark:data-hover:bg-gray-700',
	weekday: 'pb-1 text-xs font-medium text-gray-500 dark:text-gray-400',
	cell: 'p-0',
	day: 'size-9 rounded-md text-sm data-hover:bg-gray-100 data-focus:outline-2 data-focus:outline-blue-600 data-today:font-bold data-in-range:rounded-none data-in-range:bg-blue-100 data-range-start:rounded-s-md data-range-end:rounded-e-md data-range-start:bg-blue-600 data-range-start:text-white data-range-end:bg-blue-600 data-range-end:text-white data-selected:bg-blue-600 data-selected:text-white data-disabled:opacity-40 dark:data-hover:bg-gray-700 dark:data-in-range:bg-blue-900 dark:data-range-start:bg-blue-600 dark:data-range-end:bg-blue-600 dark:data-selected:bg-blue-600'
};
<script lang="ts">
	import { DateRangePicker, type DateRangePickerProps } from '@frostycle/rime/date-picker';
	import { pickerClasses } from './picker-classes.js';

	let { value = $bindable(null), ...rest }: DateRangePickerProps = $props();
</script>

<DateRangePicker bind:value transition classes={pickerClasses} {...rest} />
<DateRangeField bind:value={period} months={2} {presets} />

Validating URL values

An invalid value throws, so check anything from a URL first.

import { isIsoDate } from '@frostycle/rime/date-picker';

const from = url.searchParams.get('from');
const value = isIsoDate(from) ? from : null;

Non-modal popup

The popup uses the native popover attribute, so it is not clipped by overflow: hidden parents and works inside a modal <dialog>. It deliberately does not trap focus: tabbing out closes it and discards a half-made range. In a two-month view, the Next control sits in the last month's header, so it follows the first month's grid in tab order.