oakoss/ui
Components

Date Field

A date input with one editable segment per unit, ordered for the locale.

SourceReact Aria
Due dateWhen the invoice is due.

Installation

npx shadcn@latest add @oakoss/date-field

Usage

import { parseDate } from '@internationalized/date';

import { DateField } from '#/components/ui/inputs/date-field';

<DateField defaultValue={parseDate('2026-03-14')} label="Due date" />;

Values are Internationalized Date objects, not Date: CalendarDate for a day, CalendarDateTime for a day and time, and ZonedDateTime for a moment in a time zone. parseDate reads an ISO string such as 2026-03-14, and value.toString() writes one back.

Each unit is its own segment, in the order and with the digits of the user's locale, so nobody has to guess whether 3/4 means March or April. Type digits into a segment or step it with the arrow keys; there's no free text to parse. For a calendar as well, use Date Picker, or Date Range Picker for a start and end.

Examples

Granularity

granularity sets the smallest segment: day (the default for dates), hour, minute or second, which needs a CalendarDateTime or ZonedDateTime value. A ZonedDateTime shows its time zone, which hideTimeZone hides.

Meeting
Launch

Validation

minValue, maxValue and isDateUnavailable validate the value, with React Aria's translated message unless you pass errorMessage. With the default validationBehavior="native", errors show when the form is submitted; validationBehavior="aria" shows them as soon as the value breaks a rule.

Check-inValue must be 3/1/2026 or later.

Accessibility

React Aria handles:

  • Segments: a group named by the label, with a spinbutton per unit named for its unit and the field ("month, Due date"). On iOS they're text boxes, since VoiceOver can't focus a spinbutton there. Separators are hidden from screen readers.
  • Keyboard: ← and → move between segments, in the locale's direction; digits fill a segment and move on once it's full; ↑ and ↓ step it, Page Up and Page Down step further, and Home and End go to its first and last value; Backspace clears digits and moves back from an empty segment.
  • Forms: the value as an ISO string in a hidden input when you pass name.

The field draws a single border and focus outline around its segments, as an Input does. A focused segment fills with the accent color, or red while the field is invalid, and in Windows High Contrast with the system's highlight color. A disabled field fades, and its segments take the system's disabled color in High Contrast.

Known React Aria issues: VoiceOver's own increment and decrement gestures don't change a segment (react-spectrum#8591), and segments don't support copy and paste (react-spectrum#5285).

API

DateField

Extends React Aria's DateField.

Props

Prop

Type

Also accepts all React Aria DateField props. Takes the layout props or children, not both: children replace the layout, built from the Field parts, DateFieldGroup and DateInput.

Data attributes

AttributePresent when
data-slotAlways: date-field
data-disabledThe field is disabled
data-invalidThe field is invalid
data-readonlyThe field is read-only
data-requiredThe field is required

DateFieldGroup

The border around a DateInput, for a layout of your own. It takes size, start and end like the field.

DateInput

React Aria's DateInput with a DateSegment per unit, which scrolls sideways when a long locale outgrows the field.

Data attributes

AttributePresent when
data-slotAlways: date-input
data-focus-withinA segment has focus
data-invalidThe field is invalid
data-disabledThe field is disabled

DateSegment

One unit of the value, or a separator.

Data attributes

AttributePresent when
data-slotAlways: date-segment
data-typeAlways: the unit (year, month, day, hour, …), or literal for a separator
data-placeholderThe segment has no value yet
data-invalidThe field is invalid
data-disabledThe field is disabled