UI Kit components
Jira UI Kit components
UI Kit hooks
Forge bridge APIs
Jira bridge APIs
Upgrade UI Kit versions
Previous versions

Time picker (Preview)

To add the TimePicker component to your app:

1
2
import { TimePicker } from '@forge/react';

Description

A time picker allows the user to select a specific time.

Props

NameTypeRequiredDescription
appearance"default" | "subtle" | "none"NoSet the appearance of the picker.
subtle will remove the borders, background, and icon.
aria-invalid"true" | "false"No
aria-labelledbystringNo
autoFocusbooleanNoSet the picker to autofocus on mount.
defaultIsOpenbooleanNoThe default for isOpen.
defaultValuestringNoThe default for value.
hideIconbooleanNoHides icon for dropdown clear indicator.
idstringNoSet the id of the field.
Associates a Label with the field.
isDisabledbooleanNoSet if the field is disabled.
isInvalidbooleanNoSet if the picker has an invalid value.
isOpenbooleanNoSet if the dropdown is open. Will be false if not provided.
labelstringNoAccessible name for the Time Picker Select, rendered as aria-label. This will override any other method of providing a label.
localestringNoLocale used to format the time. See DateTimeFormat.
namestringNoThe name of the field.
onBlur(event: FocusEvent) => voidNoCalled when the field is blurred.
onChange(value: string) => voidNoCalled when the value changes. The only argument is an ISO time or empty string.
onFocus(event: FocusEvent) => voidNoCalled when the field is focused.
placeholderstringNoPlaceholder text displayed in input.
selectPropsSelectProps<any, false>NoProps to apply to the select.
spacing"default" | "compact"NoThe spacing for the select control.
timeFormatstringNoTime format that is accepted by date-fns's format function.
timeIsEditablebooleanNoSet if users can edit the input, allowing them to add custom times.
timesstring[]NoThe times shown in the dropdown.
valuestringNoThe ISO time that should be used as the input value.

Examples

Default

By default, the time field is used to select a time from the select menu. Example image of default time picker Example image of default time picker opened

1
2
import { Label, TimePicker } from "@forge/react";

const TimePickerDefaultExample = () => {
  return (
    <Label labelFor="default-time-picker-example">Choose time</Label>
    <TimePicker
    selectProps={{
        inputId: "default-time-picker-example",
    }}
    />
  );
};

Form

When using the time picker with the form component, include a label and helper text. For more information, see the form component.

Example image of time picker in a form

1
2
import {
  Button,
  useForm,
  Form,
  FormFooter,
  Label,
  RequiredAsterisk,
} from "@forge/react";

const TimePickerFormExample = () => {
  const { handleSubmit, register, getFieldId } = useForm();
  return (
    <>
      <Form onSubmit={handleSubmit(console.log)}>
        <Label labelFor={getFieldId("time-picker")}>
          Scheduled run time <RequiredAsterisk />
        </Label>
        <TimePicker
          {...register("time-picker")}
          selectProps={{
            inputId: getFieldId("time-picker"),
          }}
        />
        <FormFooter>
          <Button appearance="primary" type="submit">
            Submit
          </Button>
        </FormFooter>
      </Form>
    </>
  );
};

Field label and message

Always use a label component for each field and associate the label to the field properly. Use the HelperMessage component for any optional field-related message.

Required field label

For required fields, always add RequiredAsterisk component next to the label.

Validation

This is how time picker behaves within forms.

Validation displays an error message related to the restrictions of the time picker.

When a user selects the time picker area, the focus color changes to blue. When validating time pickers in real-time, message icons switch based on the message type.

For example, helper text becomes an error message when the input content doesn't meet the criteria. Error and warning messages disappear when the criteria is met.

Keep helper text as short as possible. For complex information, provide a link to more information in a new browser tab. Use the messaging guidelines for more help.

Example image of invalid time picker in a form Example image of valid time picker in a form

1
2
import { 
    TimePicker
    Label,
    useForm,
    Form,
    FormFooter,
    Button,
    ErrorMessage,
    HelperMessage,
    ValidMessage,
    RequiredAsterisk
} from "forge/react";

const TimePickerFormValidationExample = () => {
  const { handleSubmit, register, getFieldId, formState } = useForm();
  const { errors, touchedFields } = formState;

  return (
    <Form onSubmit={handleSubmit(console.log)}>
        <Label labelFor={getFieldId("time-picker")}>
            Scheduled run time <RequiredAsterisk />
        </Label>
        <TimePicker
            {...register("time-picker", { required: true })}
            selectProps={{
                inputId: getFieldId("time-picker"),
            }}
        />
        {errors["time-picker"] && (
            <ErrorMessage>This field is required</ErrorMessage>
        )}
        {!touchedFields["time-picker"] && !errors["time-picker"] && (
            <HelperMessage>Help or instruction text goes here</HelperMessage>
        )}
        {touchedFields["time-picker"] && !errors["time-picker"] && (
            <ValidMessage>You have entered a valid datetime</ValidMessage>
        )}
        <FormFooter>
            <Button appearance="primary" type="submit">
                Submit
            </Button>
        </FormFooter>
    </Form>
  );
};

Internationalization

Locale

Use locale to display times in a format which is appropriate to users.

Example image of time picker with locale

1
2
import { TimePicker, Label } from "@forge/react";

export const TimePickerLocaleExample = () => {
  return (
    <>
      <Label labelFor="timepicker-locale-en">English locale</Label>
      <TimePicker
          locale="en-US"
          selectProps={{
              inputId: "timepicker-locale-en",
          }}
      />
      <Label labelFor="timepicker-locale-ko">Korean locale</Label>
      <TimePicker
          locale="ko-KR"
          selectProps={{
              inputId: "timepicker-locale-ko",
          }}
      />
    </>
  )
}

Time formats

TimePicker supports customizing the format of times. Formats are given as strings and use the syntax specified at Modern JavaScript Date Utility Library.

  • `timeFormat` determined how times are formatted.

Where possible use locale for time formatting, instead of a custom format.

Time formats should be informed by the user’s locale and the use case.

Example image of time picker with custom time format

1
2
import { TimePicker, Label } from "@forge/react";

const TimePickerCustomTimeFormat = () => {
  return (
    <Label labelFor="timepicker-custom-format">Custom Time Format</Label>
    <TimePicker
      timeFormat="HH:mm"
      placeholder="13:30"
      selectProps={{
        inputId: "timepicker-custom-format",
      }}
    />
  )
}

Time editable

This allows the time field to be edited via keyboard prompts.

Example image of default time picker

1
2
import { TimePicker, Label } from "@forge/react";

const TimePickerEditableExample = () => (
  <>
    <Label labelFor="timepicker-editable-time">Editable time example</Label>
    <TimePicker
      timeIsEditable
      selectProps={{
        inputId: "timepicker-editable-time",
      }}
    />
  </>
);

Rate this page: