Date Range Field
Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Focus is fully managed
- Localization support
- Highly composable
- Accessible by default
- Supports both date and date-time formats
Preface
The component works with the Temporal API: its values are Temporal.PlainDate, Temporal.PlainDateTime or Temporal.ZonedDateTime. Reka UI does not bundle a Temporal implementation, so on runtimes without native Temporal your app loads a polyfill. See Dates & Times for the setup and how the components treat calendars and time zones.
Installation
On runtimes without native Temporal, install a polyfill and load it once, before the app mounts.
$ npm add temporal-polyfill-lite// main.ts
import { install } from 'temporal-polyfill-lite/shim'
install(false) // keeps the native Temporal when the browser has oneInstall the component from your command line.
$ npm add reka-uiAnatomy
Import all parts and piece them together.
<script setup>
import {
DateRangeFieldInput,
DateRangeFieldRoot,
} from 'reka-ui'
</script>
<template>
<DateRangeFieldRoot>
<DateRangeFieldInput />
</DateRangeFieldRoot>
</template>API Reference
Root
Contains all the parts of a date field
| Data Attribute | Value |
|---|---|
[data-readonly] | Present when readonly |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
Input
Contains the date field segments
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-placeholder] | Present when no value is set |
Real-world examples
- Date Picker Selection: Date pickers let users select a date or a range of dates. They commonly use in booking systems.
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Tab | When focus moves onto the date field, focuses the first segment. |
ArrowLeftArrowRight |
Navigates between the date field segments.
|
ArrowUpArrowDown | Increments/changes the value of the segment. |
0-9 |
When the focus is on a numeric DateFieldInput, it types in the number and focuses the next segment if the next input would result in an invalid value.
|
Backspace | Deletes a digit from the focused numeric segments. |
AP | When the focus is on the day period, it sets it to AM or PM. |
Headless composable
useDateRangeField is the range counterpart of useDateField: it holds startValue and endValue, setRangeValue(), the segments of both dates and createInputSurface(part, type) for each one. It registers watchers and collects the segment elements on mount, so call it inside setup(). The composable is experimental; see Headless composables.
