VayuUI

DatePicker

A comprehensive date and range selection component with multiple view modes.

Installation

npx vayu-ui init #one time only
npx vayu-ui add date-picker
npx vayu-ui add -t date-picker #with test case needs

Usage

DatePicker Component

WCAG 2.2 AA Compliant • Keyboard Navigation • Range Selection • Disabled Dates

Single Date Selection

Select a single date from the calendar

Basic

Selected: none

Date Range Selection

Select a start and end date

Range

Range: none

Disabled Weekdays

Disable weekends (Saturdays & Sundays)

No Weekends

Selected: none

Note: Weekends are shown with strikethrough and cannot be selected

Disabled Specific Dates

Block specific dates (holidays, blocked days)

Blocked

Selected: none

Blocked dates: 15th, 20th of this month, and 1st of next month

Keyboard Navigation

Full keyboard support for accessibility

WCAG 2.2 AA

Navigation

  • Previous day
  • Next day
  • Previous week
  • Next week

Actions

  • Enter Select date
  • Escape Close calendar
  • Home First day of month
  • End Last day of month
  • PgUp/PgDn Prev/Next month

Range with Disabled Weekends

Range selection that skips weekends

Combined

Range selection with weekends disabled - useful for booking business days

Disabled State

The entire date picker can be disabled

<DatePicker mode="single">
  <DatePicker.Trigger placeholder="Select date" />
  <DatePicker.Calendar>
    <DatePicker.Calendar.Footer />
  </DatePicker.Calendar>
</DatePicker>

<DatePicker mode="range">
  <DatePicker.Trigger placeholder="Select date range" />
  <DatePicker.Calendar>
    <DatePicker.Calendar.Footer />
  </DatePicker.Calendar>
</DatePicker>

Anatomy

<DatePicker>
  <DatePicker.Trigger />
  <DatePicker.Calendar>
    <DatePicker.Calendar.Footer />
  </DatePicker.Calendar>
</DatePicker>

Accessibility

  • Keyboard support: Arrow keys navigate between dates, months, and years. Space and Enter select the focused date. Escape closes the calendar.
  • ARIA attributes: Proper focus management, aria-expanded on the trigger, and standard calendar grid aria features are supported.
  • Focus behavior: Focus is trapped within the calendar popup when opened and returns to the trigger when closed.

Screen reader behavior

Screen readers announce the trigger state (expanded or collapsed) and the currently selected date. Once the calendar is open, the visible month and year are announced, and moving focus through dates accurately speaks each date, its selection status, and any disabled status.

Component Folder Structure

DatePicker/
├── DatePicker.tsx
├── DatePickerCalendar.tsx
├── DatePickerDropDowns.tsx
├── DatePickerFooter.tsx
├── DatePickerIcons.tsx
├── DatePickerTrigger.tsx
├── index.ts
├── types.ts
└── utils.ts

Props

DatePicker

PropTypeDescription
mode'single' | 'range'Controls the selection mode (defaults to 'single').
valueDate | DateRange | nullThe controlled value of the date picker.
defaultValueDate | DateRange | nullThe initial value when uncontrolled.
onChange(value: DatePickerValue) => voidCallback triggered when the date or range changes.
disabledbooleanIf true, disables the functionality.
disabledWeekdaysnumber[]Array of days to disable (0 for Sunday to 6 for Saturday).
disabledDatesDate[]Specific dates that are disabled from selection.
placeholderstringFallback text used internally.

DatePicker.Trigger

PropTypeDescription
placeholderstringDisplayed text when no date is selected.

DatePicker.Calendar

PropTypeDescription
inheritsHTMLAttributes<HTMLDivElement>Standard HTML attributes for styling and events.

DatePicker.Calendar.Footer

PropTypeDescription
inheritsHTMLAttributes<HTMLDivElement>Standard HTML attributes for styling and events.

On this page