Beta Preview

DateField

DateFields allow users to enter and edit date and time values using a keyboard. Each part of a date value is displayed in an individually editable segment.

Birth date
 
size 
 
contextualHelp 
isDisabled 
import {DateField} from '@react-spectrum/s2';

<DateField label="Birth date" />

Value

Use the value or defaultValue prop to set the date value, using objects in the @internationalized/date package. This library supports parsing date strings in multiple formats, manipulation across international calendar systems, time zones, etc.

Selected date: Monday, February 3, 2020

import {parseDate, getLocalTimeZone} from '@internationalized/date';
import {useDateFormatter} from 'react-aria';
import {DateField} from '@react-spectrum/s2';
import {useState} from 'react';

function Example() {
  let [date, setDate] = useState(parseDate('2020-02-03'));
  let formatter = useDateFormatter({ dateStyle: 'full' });
  
  return (
    <>
      <DateField
        value={date}
        onChange={setDate} />
      <p>Selected date: {date ? formatter.format(date.toDate(getLocalTimeZone())) : '--'}</p>
    </>
  );
}

Format options

The date format is automatically determined based on the user's locale. DateField supports several props to control how values are displayed.

Date
granularity 
hourCycle 
hideTimeZone 
shouldForceLeadingZeros 
import {parseZonedDateTime} from '@internationalized/date';
import {DateField} from '@react-spectrum/s2';

<DateField
  label="Date"
  defaultValue={parseZonedDateTime('2025-02-03T08:45:00[America/Los_Angeles]')} />

International calendars

By default, DateField displays the value using the calendar system for the user's locale. Use <Provider> to override the calendar system by setting the Unicode calendar locale extension. The onChange event always receives a date in the same calendar as the value or defaultValue (Gregorian if no value is provided), regardless of the displayed locale.

Locale
Calendar
import {Provider, DateField} from '@react-spectrum/s2';
import {parseZonedDateTime} from '@internationalized/date';

<Provider locale="hi-IN-u-ca-indian">
  <DateField defaultValue={parseZonedDateTime('2025-02-03T08:45:00[America/Los_Angeles]')} />
</Provider>

Forms

Use the name prop to submit the selected date to the server as an ISO 8601 string. Set the isRequired, minValue, or maxValue props to validate the value, or implement custom client or server-side validation. See the Forms guide to learn more.

Appointment date 
isRequired 
necessityIndicator 
import {today, getLocalTimeZone} from '@internationalized/date';
import {DateField, Form, Button} from '@react-spectrum/s2';

function Example(props) {
  return (
    <Form>
      <DateField
        {...props}
        label="Appointment date"
        name="date"
        isRequired
        minValue={today(getLocalTimeZone())}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

NameTypeDefault
size'S''M''L''XL'Default: 'M'
The size of the DateField.
isDateUnavailable(date: ) => booleanDefault:
Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.
placeholderValuenullDefault:
A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight.
hourCycle1224Default:
Whether to display the time in 12 or 24 hour format. By default, this is determined by the user's locale.
granularityDefault:
Determines the smallest unit that is displayed in the date picker. By default, this is "day" for dates, and "minute" for times.
hideTimeZonebooleanDefault: false
Whether to hide the time zone abbreviation.
shouldForceLeadingZerosbooleanDefault:
Whether to always show leading zeros in the month, day, and hour fields. By default, this is determined by the user's locale.
isDisabledbooleanDefault:
Whether the input is disabled.
isReadOnlybooleanDefault:
Whether the input can be selected but not changed by the user.
stylesDefault:
Spectrum-defined styles, returned by the style() macro.
valuenullDefault:
The current value (controlled).
defaultValuenullDefault:
The default value (uncontrolled).
onChange(value: <> | null) => voidDefault:
Handler that is called when the value changes.