Skip to content

Material 3

Components

Date field

Date fields let people enter a date with the keyboard.

9:30
Plan a stayLake Louise, Alberta
MM/DD/YYYY
MM/DD/YYYY

Date fields let people type a date with the keyboard. Use a DateField for an outlined text field in which a date is typed, as in the input mode of the date pickers.

To let people pick the date on a calendar, use a date picker.

import { DateField } from '@material-web/react'
import { parseDate } from '@internationalized/date'

Basic date field

Set the label text with label and the date with defaultValue. The date is typed in segments, and each segment shows a placeholder until it is typed. A DateField takes no children.

MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'

export default function Basic() {
  return <DateField label="Date" defaultValue={parseDate('2025-08-17')} className="w-80" />
}

Label and supporting text

Set label to the label text, which names the field. The label rests on the date's line while the field is empty and not focused, and moves to the outline otherwise. With isRequired, it ends in an asterisk. Without a label, set an aria-label: the segments then show the date's format while the field is empty.

MM/DD/YYYY
MM/DD/YYYY
MM/DD/YYYY
import { DateField } from '@material-web/react'

export default function Label() {
  return (
    <>
      <DateField label="Date" className="w-52" />
      <DateField label="Date" isRequired className="w-52" />
      <DateField aria-label="Date" className="w-52" />
    </>
  )
}

Supporting text

Set description to the text under the field. Without it, the text is the date's format, such as MM/DD/YYYY. Pass null to show no text. While the field is invalid, the error text follows it.

MM/DD/YYYY
The day you arrive
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'

export default function Description() {
  const date = parseDate('2025-08-17')
  return (
    <div className="flex flex-wrap items-start justify-center gap-space-200">
      <DateField label="Check-in" defaultValue={date} className="w-52" />
      <DateField
        label="Check-in"
        description="The day you arrive"
        defaultValue={date}
        className="w-52"
      />
      <DateField label="Check-in" description={null} defaultValue={date} className="w-52" />
    </div>
  )
}

Trailing icon

Set trailing to show an icon or an icon button at the end of the field, such as a calendar button that opens a date picker. In this example, the button is in a DialogTrigger with a DatePickerDialog, whose confirm button sets the field's value.

MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import {
  Button,
  DateField,
  DatePicker,
  DatePickerCalendar,
  DatePickerContent,
  DatePickerDialog,
  DatePickerHeader,
  DatePickerHeadline,
  DialogTrigger,
  Icon,
  IconButton,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, type DateValue } from 'react-aria-components'

export default function WithDatePicker() {
  const [date, setDate] = useState<DateValue | null>(parseDate('2025-08-17'))
  const [picked, setPicked] = useState(date)
  return (
    <DateField
      label="Date"
      value={date}
      onChange={setDate}
      className="w-80"
      trailing={
        <DialogTrigger onOpenChange={(isOpen) => isOpen && setPicked(date)}>
          <IconButton aria-label="Calendar">
            <Icon name="calendar_today" />
          </IconButton>
          <DatePickerDialog
            dismissButton={
              <Button variant="text" slot="close">
                Cancel
              </Button>
            }
            confirmButton={
              <Button
                variant="text"
                slot="close"
                isDisabled={!picked}
                onPress={() => setDate(picked)}
              >
                OK
              </Button>
            }
          >
            <DatePicker value={picked} onChange={setPicked} autoFocus>
              <DatePickerHeader>
                <Heading slot="title">Select date</Heading>
                <DatePickerHeadline>Selected date</DatePickerHeadline>
              </DatePickerHeader>
              <DatePickerContent>
                <DatePickerCalendar />
              </DatePickerContent>
            </DatePicker>
          </DatePickerDialog>
        </DialogTrigger>
      }
    />
  )
}
  • An icon button is a tab stop after the segments. Give it an aria-label that says what it does. A button in trailing is disabled with the field, unless it sets isDisabled={false} itself.
  • trailing can also be a function of the field's state: isInvalid, isDisabled, isReadOnly and isRequired.

Controlled

Pass the date as a CalendarDate from @internationalized/date. Set the initial date with defaultValue, and the field keeps the date itself. To keep the date in your own state, control the field with value and onChange, which is called as a date is typed, and with null once every segment is cleared.

MM/DD/YYYY
2025-08-17
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'
import { useState } from 'react'
import type { DateValue } from 'react-aria-components'

export default function Value() {
  const [date, setDate] = useState<DateValue | null>(parseDate('2025-08-17'))
  return (
    <div className="flex flex-col gap-space-100">
      <DateField label="Date" value={date} onChange={setDate} className="w-80" />
      <span className="px-space-200 text-body-md text-on-surface-variant">
        {date ? date.toString() : 'null'}
      </span>
    </div>
  )
}

Form props

Set isReadOnly to keep the date from being changed, and isDisabled to disable the field.

MM/DD/YYYY
MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'

export default function ReadOnlyAndDisabled() {
  const date = parseDate('2025-08-17')
  return (
    <>
      <DateField label="Read-only" defaultValue={date} isReadOnly className="w-52" />
      <DateField label="Disabled" defaultValue={date} isDisabled className="w-52" />
    </>
  )
}

Validation

Set isInvalid to show the field and its supporting text in the error color.

The field can also check the date itself, as React Aria's DateField does:

  • Bounds: Set minValue and maxValue to the first and the last date allowed.
  • Unavailable dates: Pass a function to isDateUnavailable that returns true for a date that is not allowed.
  • Your own rule: Pass a function to validate that returns an error message for a date, or null.

A date that fails a check puts the field in the error state once the focus leaves the field, and the error text is shown under the supporting text. In this example, type a date outside September 2025 into the second field, then leave the field.

Pick a day in September
A day in September 2025
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'

export default function Validation() {
  return (
    <div className="flex flex-wrap items-start justify-center gap-space-200">
      <DateField
        label="Invalid"
        description="Pick a day in September"
        defaultValue={parseDate('2025-08-17')}
        isInvalid
        className="w-64"
      />
      <DateField
        label="Check-in"
        description="A day in September 2025"
        minValue={parseDate('2025-09-01')}
        maxValue={parseDate('2025-09-30')}
        className="w-64"
      />
    </div>
  )
}

Forms

Set a name to include the field in a form. The date is submitted as YYYY-MM-DD, and a form reset restores the initial date. Set isRequired to block the form from being submitted while the field is empty. The browser's own message is then shown as the error text.

A date that fails a check under Validation, or a field that is isInvalid, blocks the form too, unless validationBehavior is aria. See React Aria's Forms guide.

MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import { Button, DateField } from '@material-web/react'
import { useState } from 'react'
import { Form } from 'react-aria-components'

export default function InForm() {
  const [sent, setSent] = useState<string | null>(null)
  return (
    <Form
      className="flex flex-col items-start gap-space-300"
      onSubmit={(event) => {
        event.preventDefault()
        setSent(String(new FormData(event.currentTarget).get('date')))
      }}
      onReset={() => setSent(null)}
    >
      <DateField label="Date" name="date" defaultValue={parseDate('2025-08-17')} className="w-80" />
      <div className="flex gap-space-100">
        <Button variant="text" type="reset">
          Reset
        </Button>
        <Button type="submit">Submit</Button>
      </div>
      {sent && <p className="m-0 text-body-md text-on-surface-variant">Sent: {sent}</p>}
    </Form>
  )
}

Localization

The field formats the date for the locale: the order of the segments, their separators and placeholders, and the format in the supporting text. The locale is the browser's by default. To set another, wrap the field in an I18nProvider from react-aria-components. See Internationalization.

DD/MM/YYYY
TT.MM.JJJJ
年/月/日
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'
import { I18nProvider } from 'react-aria-components'

export default function Locale() {
  const date = parseDate('2025-08-17')
  return (
    <>
      <I18nProvider locale="en-GB">
        <DateField label="Date" defaultValue={date} className="w-52" />
      </I18nProvider>
      <I18nProvider locale="de-DE">
        <DateField label="Datum" defaultValue={date} className="w-52" />
      </I18nProvider>
      <I18nProvider locale="ja-JP">
        <DateField label="日付" defaultValue={date} className="w-52" />
      </I18nProvider>
    </>
  )
}

Date format

The format is the locale's, and no prop sets another. The segments are written with leading zeros: shouldForceLeadingZeros is true by default. Set it to false to write the digits as the locale does, such as 8/7/2025 in US English.

MM/DD/YYYY
MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'
import { I18nProvider } from 'react-aria-components'

export default function Format() {
  const date = parseDate('2025-08-07')
  return (
    <I18nProvider locale="en-US">
      <DateField label="Leading zeros" defaultValue={date} className="w-52" />
      <DateField
        label="Locale's digits"
        defaultValue={date}
        shouldForceLeadingZeros={false}
        className="w-52"
      />
    </I18nProvider>
  )
}

Customization

Pass classes in className to size and place one field. See Styling for the classes, the states and the theme.

  • Element: A date field is an inline flex box, aligned to the top of its line. className, style and ref apply to its outermost element.
  • Width: Set the field's width in className, such as w-80, or w-full to make the field as wide as the element it is in. Without a width, the field is as wide as its date.
  • States: On the field, style the disabled, invalid, read-only and required states with their variants, such as invalid:. Hover and focus are reported inside the field: use the has-* form for them, as in has-hover:bg-surface-container. See Variants.
  • Functions: className and style can be functions of isDisabled, isInvalid, isReadOnly and isRequired, as trailing can. For hover and focus, pass a function as input.
  • Every field: To restyle all the date fields at once, change the theme.

Custom input

Pass a function to input to render a <div> of your own around the date, in place of the field's. It is called with the props to spread on your element, including the segments and ref, and with the input's state, such as isFocusWithin and isInvalid. In this example, the element has a title, which the browser shows over the date.

MM/DD/YYYY
import { parseDate } from '@internationalized/date'
import { DateField } from '@material-web/react'

export default function CustomInput() {
  return (
    <DateField
      label="Date"
      defaultValue={parseDate('2025-08-17')}
      input={(props) => <div {...props} title="Month, day and year" />}
      className="w-80"
    />
  )
}

Limitations

Variant and density

A date field is always outlined and 56dp tall. It has no variant, and the density classes do not change its height.

Floating label

The label on the outline extends above the field's top edge. If a scrolling box starts with a date field, give the box pt-space-100 so that the label is not cut off. A label wider than the field is cut off with an ellipsis, so keep it short.

Error text language

The error texts that the field writes itself, such as Value must be 09/01/2025 or later., are in the browser's language, not in the locale of an I18nProvider. For an error text in a language you choose, return it from validate.