DateField
React Date Field components allow users to select a specific date value using a segment-based input. They are commonly used in booking forms, event scheduling, date filters, and registration flows where precise keyboard entry is preferred.
Installation
The Date Field relies on the react-aria-components library.
Install the component using the Tailgrids CLI.
npx @tailgrids/cli add date-fieldAnatomy
import { Label } from "@/components/tailgrids/core/label";
import { Description } from "@/components/tailgrids/core/description";
import { DateField } from "@/components/tailgrids/core/date-field";
import { DateInput, DateSegment } from "@/components/tailgrids/core/date-field";
export const DateFieldExample = () => (
<DateField>
<Label>Appointment date</Label>
<DateInput>{segment => <DateSegment segment={segment} />}</DateInput>
<Description>Select your preferred appointment date.</Description>
</DateField>
);Examples
Basic Usage
A standard date field implementation using segments for precise date entry.
Controlled
Manage the date value externally using the value and onChange props.
Uncontrolled
An uncontrolled date field with a defaultValue prop.
Disabled
A disabled date field prevents user interaction.
Validation
Display error messages and validation states when the date value is outside the allowed range.
With Date and Time
Combine date and time by using a CalendarDateTime value. Set granularity to "minute" to expose time segments.
With Min / Max
Constrain the selectable date range using minValue and maxValue.
With Leading Zeros
Use the shouldForceLeadingZeros prop to display leading zeros in day and month segments.
International Calendar
Wrap the DateField with an I18nProvider and set the locale prop to use a different calendar system.
API Reference
DateField
The field container that provides context for the date input and segments. Manages state, validation, and ARIA attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
value | DateValue | null | - | The current date value (controlled). |
defaultValue | DateValue | null | - | The default date value (uncontrolled). |
onChange | (value: DateValue | null) => void | - | Handler called when the value changes. |
name | string | - | The name of the input, used when submitting an HTML form. |
form | string | - | The <form> element to associate the input with. |
id | string | - | The element's unique identifier. |
autoFocus | boolean | false | Whether the input should receive focus on mount. |
granularity | 'day' | 'hour' | 'minute' | 'second' | 'day' | The smallest unit of date/time to display. |
hourCycle | 12 | 24 | - | Whether to use 12-hour or 24-hour format. |
hideTimeZone | boolean | false | Whether to hide the time zone abbreviation. |
shouldForceLeadingZeros | boolean | false | Whether to always show leading zeros in day and month. |
minValue | DateValue | - | The minimum allowed date. |
maxValue | DateValue | - | The maximum allowed date. |
placeholderValue | DateValue | - | A placeholder date value when no value is set. |
orientation | 'vertical' | 'horizontal' | 'responsive' | 'vertical' | Layout direction of the field container. |
disabled | boolean | false | Whether the input is disabled. |
readOnly | boolean | false | Whether the input is read only. |
required | boolean | false | Whether the input is required. |
invalid | boolean | false | Whether the input is shown in an invalid state. |
validate | (value: DateValue) => ValidationResult | true | null | undefined | - | Custom validation function for the date value. |
validationBehavior | 'aria' | 'native' | 'native' | Whether to use native HTML or ARIA form validation. |
aria-label | string | - | Defines a string that labels the current element. |
aria-labelledby | string | - | Identifies the element (or elements) that label the element. |
aria-describedby | string | - | Identifies the element that describes the object. |
aria-details | string | - | Identifies the element providing extended description. |
onBlur | (e: FocusEvent) => void | - | Handler called when the element loses focus. |
onFocus | (e: FocusEvent) => void | - | Handler called when the element receives focus. |
onFocusChange | (isFocused: boolean) => void | - | Handler called when the element's focus status changes. |
onKeyDown | (e: KeyboardEvent) => void | - | Handler called when a key is pressed. |
onKeyUp | (e: KeyboardEvent) => void | - | Handler called when a key is released. |
className | string | - | Additional CSS classes to apply to the container. |
DateInput
The styled input container that wraps date segments. Supports visual state variants for form feedback.
| Prop | Type | Default | Description |
|---|---|---|---|
state | 'default' | 'error' | 'success' | 'default' | Visual state variant for the input container. |
className | string | ((props: RenderProps) => string) | - | Additional CSS classes or render-prop className. |
DateSegment
An individual editable segment of the date (day, month, year, hour, etc.).
| Prop | Type | Default | Description |
|---|---|---|---|
segment | DateSegment | - | The segment object from the DateInput render prop. |
className | string | ((props: DateSegmentRenderProps) => string) | - | Additional CSS classes or render-prop className. |
See the React Aria DateField documentation for more details.
Composition
The Date Field is composed of the root DateField component plus DateInput and DateSegment. It can be combined with shared field components (Label, Description, FieldError) for a complete form control.
DateField — Root container. Manages date state, validation, and ARIA context.
├── Label — Visible label.
├── DateInput — Groups editable segments into a styled input area.
│ └── DateSegment — Individual editable segment (day, month, year, hour, minute).
└── Description — Helper text.- Use
DateFieldas the root. It provides the date value, validation state, and keyboard context to all children. - Use
Labelto label the field. It is automatically linked to the input. - Use
DateInputto render the segment group. It accepts a render function that receives eachsegmentand returns aDateSegment. - Use
DateSegmentinsideDateInputto render each editable part of the date. It handles focus, typing, and arrow-key incrementing. - Use
Descriptionfor helper text. It is automatically announced by screen readers. - Use
FieldErrorfor validation messages. It is linked viaaria-errormessagewheninvalidis set.
Accessibility
- Keyboard Support: Users can navigate between date segments (day, month, year) using
Arrowkeys and edit values using the number keys. - Screen Readers: Each segment is properly labeled and provides live updates to screen readers as values change.
- Focus Management: Focus is managed automatically between segments for a seamless typing experience.
