DatePicker

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 DatePicker component combines a date input field with a calendar popup, offering users a flexible way to select dates. It supports both keyboard and mouse interactions, with built-in validation and formatting capabilities.

When to use

Use the DatePicker component when:

Implementation

The DatePicker 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-picker/5.x.x/tt-date-picker.js"></script>

Usage

Basic usage

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

With initial value

<tt-date-picker value="2024-01-30"></tt-date-picker>

Attributes

Attribute Type Default Description
value Date undefined The selected date value
name string undefined Name attribute for form association
openLeft boolean false Open the calendar on the left side of the input

Parts

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

Keyboard Navigation

Date Input

The date input field supports the following keyboard interactions:

Calendar

When the calendar popup is open:

Form Integration

The DatePicker component is form-associated and will:

Validation

The component includes built-in validation for:

Events

Event Detail Type Description
change Date Fired when a date is selected or input is completed
date-selection Date Fired when a date is selected from the calendar

Best Practices

  1. Always provide clear labels for date pickers
  2. Consider using placeholder text to show the expected date format
  3. Implement appropriate min/max date constraints for your use case
  4. Ensure sufficient space around the component for the calendar popup
  5. Test keyboard navigation and screen reader compatibility
  6. Consider the locale when displaying date formats

Accessibility

Example with Form

<form>
  <label for="appointment-date">Select Appointment Date</label>
  <tt-date-picker id="appointment-date" name="appointment" required></tt-date-picker>
  <button type="submit">Submit</button>
</form>

Styling

Example of custom styling:

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

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