Beta Preview

TimeField

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

Event time
 
granularity 
size 
labelPosition 
 
contextualHelp 
isDisabled 
import {TimeField} from '@react-spectrum/s2';

<TimeField label="Event time" />

Value

Use the value or defaultValue prop to set the time value, using objects in the @internationalized/date package. TimeField accepts plain Time, CalendarDateTime, or ZonedDateTime, but only displays the time.

Selected time: 11:45:00

import {Time} from '@internationalized/date';
import {TimeField} from '@react-spectrum/s2';
import {useState} from 'react';

function Example() {
  let [time, setTime] = useState(new Time(11, 45));
  
  return (
    <>
      <TimeField
        value={time}
        onChange={setTime} />
      <p>Selected time: {time ? time.toString() : '--'}</p>
    </>
  );
}

Format options

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

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

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

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 time 
isRequired 
necessityIndicator 
import {Time} from '@internationalized/date';
import {TimeField, Form, Button} from '@react-spectrum/s2';

function Example(props) {
  return (
    <Form>
      <TimeField
        {...props}
        label="Appointment time"
        name="time"
        isRequired
        minValue={new Time(9)}
        maxValue={new Time(17)}
        validate={time => time?.minute % 15 !== 0 ? 'Appointments start every 15 minutes.' : null}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

NameTypeDefault
size'S''M''L''XL'Default: 'M'
The size of the TimeField.
hourCycle1224Default:
Whether to display the time in 12 or 24 hour format. By default, this is determined by the user's locale.
granularity'hour''minute''second'Default: 'minute'
Determines the smallest unit that is displayed in the time picker.
hideTimeZonebooleanDefault:
Whether to hide the time zone abbreviation.
shouldForceLeadingZerosbooleanDefault:
Whether to always show leading zeros in the hour field. By default, this is determined by the user's locale.
placeholderValueDefault:
A placeholder time that influences the format of the placeholder shown when no value is selected. Defaults to 12:00 AM or 00:00 depending on the hour cycle.
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.