Skip to main content
urbicon ui

DatePicker

A text field with a calendar popover for picking a single date.

Playground

Input Variant
Calendar Variant
<script lang="ts">
  import { DatePicker } from '@urbicon-ui/blocks';

  const label = 'Date';
  const placeholder = 'Select a date';
</script>

<DatePicker
  {label}
  {placeholder}
/>

01 Examples

Basic DatePicker

A labelled date field with a calendar popover. The bound value is a Date; the field shows it formatted for the locale.
<script lang="ts">
  import { DatePicker } from '@urbicon-ui/blocks';

  let selectedDate = $state<Date | undefined>(undefined);
</script>

<div class="max-w-xs">
  <DatePicker
    bind:value={selectedDate}
    label="Event date"
    placeholder="Select a date"
    defaultMonth={2}
    defaultYear={2026}
  />

  {#if selectedDate}
    <div class="bg-surface-elevated border-border-subtle mt-3 rounded-lg border p-3">
      <p class="text-text-secondary text-sm">
        <span class="text-text-primary font-medium">Selected:</span>
        {selectedDate.toLocaleDateString('en-US', {
          weekday: 'long',
          day: 'numeric',
          month: 'long',
          year: 'numeric'
        })}
      </p>
    </div>
  {/if}
</div>

DateRangePicker

The separate DateRangePicker picks a start and end date in two clicks, and closes once both are set. Use it for bookings or a report filter.
<script lang="ts">
  import { DateRangePicker } from '@urbicon-ui/blocks';

  let value = $state<{ start: Date; end: Date } | undefined>(undefined);
</script>

<div class="max-w-xs">
  <DateRangePicker
    bind:value
    label="Travel dates"
    placeholder="Select a range"
    defaultMonth={2}
    defaultYear={2026}
  />

  {#if value}
    <div class="bg-surface-elevated border-border-subtle mt-3 rounded-lg border p-3">
      <p class="text-text-secondary text-sm">
        <span class="text-text-primary font-medium">From:</span>
        {value.start.toLocaleDateString('en-US', {
          day: 'numeric',
          month: 'long',
          year: 'numeric'
        })}
      </p>
      <p class="text-text-secondary text-sm">
        <span class="text-text-primary font-medium">To:</span>
        {value.end.toLocaleDateString('en-US', {
          day: 'numeric',
          month: 'long',
          year: 'numeric'
        })}
      </p>
      <p class="text-text-secondary mt-1 text-xs">
        {Math.ceil((value.end.getTime() - value.start.getTime()) / (1000 * 60 * 60 * 24)) + 1} days
      </p>
    </div>
  {/if}
</div>

With Constraints

minDate and maxDate bound the calendar to March 2026; isDateDisabled locks out weekends by rule and two holidays by list. The list is a Set of toIso keys, because the picker hands the predicate its own Date objects.
Weekdays in March 2026 only, no holidays.
<script lang="ts">
  import { DatePicker } from '@urbicon-ui/blocks';
  import { toIso } from '@urbicon-ui/blocks/date';

  let selectedDate = $state<Date | undefined>(undefined);

  const minDate = new Date(2026, 2, 1);
  const maxDate = new Date(2026, 2, 31);

  // Compared by calendar day: the picker passes its own Date objects.
  const holidays = new Set([new Date(2026, 2, 6), new Date(2026, 2, 20)].map(toIso));

  function isClosed(date: Date): boolean {
    const day = date.getDay();
    return day === 0 || day === 6 || holidays.has(toIso(date));
  }
</script>

<div class="max-w-xs">
  <DatePicker
    bind:value={selectedDate}
    label="Appointment"
    placeholder="Pick a weekday"
    helper="Weekdays in March 2026 only, no holidays."
    {minDate}
    {maxDate}
    isDateDisabled={isClosed}
    defaultMonth={2}
    defaultYear={2026}
  />

  {#if selectedDate}
    <div class="bg-surface-elevated border-border-subtle mt-3 rounded-lg border p-3">
      <p class="text-text-secondary text-sm">
        <span class="text-text-primary font-medium">Appointment:</span>
        {selectedDate.toLocaleDateString('en-US', {
          weekday: 'long',
          day: 'numeric',
          month: 'long',
          year: 'numeric'
        })}
      </p>
    </div>
  {/if}
</div>

02 Accessibility

ARIA Roles

The text field carries aria-haspopup="dialog"; the calendar button beside it carries aria-expanded and, while the calendar is open, aria-controls pointing at the calendar. The calendar opens in a role="dialog" popover and is a role="grid" of day cells, with the same keyboard model as Calendar.

Keyboard Navigation

ArrowDown opens the calendar from the field, Enter or Space from the calendar button; Escape closes it. Opening leaves focus where it is, and Tab from the calendar button moves into the calendar. There the arrow keys move between days and weeks and PageUp/PageDown between months, and Escape or picking a date returns focus to the calendar button. In the field, Enter closes an open calendar and otherwise commits the date you typed. A typed date also commits when the calendar button opens the calendar and when focus leaves the picker.

Screen Reader Labels

label names the text field. Every day cell carries an aria-label with the full date ("Thursday, March 12, 2026"), and error and helper text are linked through aria-describedby.

Internationalisation

Formatting goes through the native Intl.DateTimeFormat with the configured locale, so weekday names, month names and the input format follow the language without further configuration.

03 API Reference

37 props
37 props
Prop
Type
Default
Description

04 Types

12 types
Name
Kind
Category
Used by
Description

05 Installation

Import

import { DatePicker, DateRangePicker } from '@urbicon-ui/blocks';
import type { DatePickerProps, DateRangePickerProps } from '@urbicon-ui/blocks';