DateRangePicker

Component status

Status
Is the design finished and component available in Figma library? Update required
Is the design documentation complete? Update required
Is the technical documentation complete? Up to date

Introduction

The DateRangePicker component combines date input fields with a calendar popup, enabling users to select a range of dates. It supports both keyboard and mouse interactions, with built-in validation and range constraints.

When to use

Use the DateRangePicker component when:

Implementation

The DateRangePicker is implemented as a Web Component following WAI-ARIA best practices. Import it using:

<script type="module" src="https://cdn.design-system.triptease.io/tt-date-range-picker/latest/tt-date-range-picker.js"></script>

Basic Usage

<tt-date-range-picker></tt-date-range-picker>

With constraints:

<tt-date-range-picker 
  min-days="2"
  max-days="30"
  min-date="2024-01-01"
  max-date="2024-12-31">
</tt-date-range-picker>

Attributes

Attribute Type Default Description
start Date undefined Start date of the range
end Date undefined End date of the range
min-days number undefined Minimum number of days in the range
max-days number undefined Maximum number of days in the range
min-date Date undefined Earliest selectable date
max-date Date undefined Latest selectable date

Parts

The component uses Shadow DOM and exposes the following parts for styling:

Keyboard Navigation

Date Input Fields

Each date input field supports the following keyboard interactions:

Calendar

When the calendar popup is open:

Preset Ranges

The calendar includes preset range options:

Form Integration

The DateRangePicker component is form-associated and will:

Validation

The component includes built-in validation for:

Events

Event Detail Type Description
change DateRange Fired when a date range is input manually
date-range-selection DateRange Fired when a date range is selected from the calendar

The DateRange type has the following structure:

interface DateRange {
  startDate?: Date;
  endDate?: Date;
}

Best Practices

  1. Always provide clear labels for start and end dates
  2. Set appropriate min/max day constraints for your use case
  3. Choose sensible min/max date constraints to limit selection range
  4. Ensure error messages clearly explain validation failures
  5. Test keyboard navigation and screen reader compatibility
  6. Consider the locale when displaying date formats
  7. Provide helpful preset ranges for common use cases

Accessibility

Example with Validation

<form>
  <label for="booking-dates">Select Booking Dates</label>
  <tt-date-range-picker 
    id="booking-dates"
    name="booking"
    min-days="2"
    max-days="14"
    min-date="2024-01-01"
    max-date="2024-12-31"
    required>
  </tt-date-range-picker>
  <button type="submit">Book Now</button>
</form>

Styling

Example of custom styling:

tt-date-range-picker::part(controls) {
  border-color: var(--color-primary-500);
  border-radius: var(--border-radius-md);
}

tt-date-range-picker::part(error) {
  color: var(--color-error-500);
  font-size: var(--font-size-sm);
}