<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Time Picker

A standardized and compact way for users to select a point in time or time slot.

Use Time Picker...

  • To select a time within a traditional form.

Don't use Time Picker...

Time Picker is a specialized Dropdown component that automatically formats JavaScript Date objects according to the locale provided to the SWAN Ii18n Provider using our Date/Time content guidelines.

Time slot

Use startTime and endTime on TimePickerOption to display a time slot.

The preview has been updated.

Single time

Use startTime only to display a single time option.

The preview has been updated.

Full width

Use fullWidth to grow a TimePicker to fill its container.

The preview has been updated.

With floating label

Use InputWithFloatingLabel to display a Time Picker with the label positioned inside of it, above the selection.

The preview has been updated.

Disabled

Use disabled on TimePicker to prevent it from being opened. For example, disable TimePicker until the user selects a date.

Use disabled on TimePickerOption to indicate that individual options are not relevant or available within the user’s current context.

The preview has been updated.

Time zone

Use timeZone on TimePicker to designate an IANA time zone.

The browser will automatically detect and apply the user’s timezone, so this prop is only necessary if you need to override the user’s timezone.

Additionally, the user’s timezone will be unknown when a Time Picker is rendered on the server. See our guidelines on server-side rendering [update link on docsite] to avoid hydration issues.

The preview has been updated.

Placeholder text

Use placeholderText with TimePickerOption to display text instead of a formatted time. This can be useful if you don’t want the first time to be preselected.

If value is not passed to the TimePickerOption, the value will default to the placeholderText.'

The preview has been updated.

Labels, errors, and helper text

Use the Form Field components to incorporate external labels, error messages, or helper text. These components automatically apply the necessary aria attributes to the Time Picker, eliminating the need for manual handling.

The preview has been updated.

Managing state

Controlled

Use value and onChange on TimePicker to provide a stored value and callback for managing that value. The callback will be invoked whenever a selection is changed by the user.

The preview has been updated.

Uncontrolled

Omit value and onChange to allow the browser to handle the state. Use defaultValue on TimePicker to specify the initial selected value.

The preview has been updated.

Server-side rendering

To avoid issues with hydration across time zones and locales, you should render Time Picker components as empty initially, then populate them with times after SSR. This can be done using a combination of React’s useState and useEffect hooks.

The preview has been updated.

Accessibility

See accessibility details for Forms.