TimePicker is only available in the React API for SWAN. This component requires internationalisation (i18n) to be set up in your application.
Time Picker
Time Picker is built using Dropdown, which uses the native HTML select element, so the appearance of its Dropdown list is determined by the user's browser and device.
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.
How does Time Picker meet your needs?