Skip to content

Time field

A compact field that takes what people type, with the time picker a press away.

import { TimeField } from '@windmorph/react';

Props

By name or description, across the 34 props below

TimeField 34 props

  • labeltype ReactNodeRequired

    The field's label, e.g. "Opens at".

  • valuetype Time | null

    The time (controlled); null for none.

  • defaultValuetype Time | nulldefault null

    Initial time when uncontrolled.

  • mintype Time

    Earliest time allowed.

  • maxtype Time

    Latest time allowed.

  • hourCycletype 12 | 24default the locale's

    12- or 24-hour clock, for the field and the picker. Left out, the locale's.

  • varianttype "outlined" | "filled"default "outlined"

    The field's style.

  • presentationtype "dialog" | "docked"default "dialog"

    Where the picker opens. dialog is the M3 time picker in a dialog. docked is a list of times under the field (every step minutes, within min and max) on windows 600px wide or more, for forms with many times; narrower windows still get the dialog. Not in the M3 spec, which has no docked time picker.

  • steptype numberdefault 30

    Minutes between the times a docked list offers, counted from midnight; 5 at least. It only shapes the list: any time can still be typed.

  • opentype boolean

    Whether the picker is open (controlled).

  • defaultOpentype booleandefault false

    Whether the picker starts open when uncontrolled.

  • supportingTexttype ReactNode

    Helper text below the field.

  • invalidtype boolean

    Marks the field invalid, with errorMessage below it.

  • errorMessagetype ReactNode

    Error text shown below the field while it's invalid, in place of supportingText.

  • requiredtype booleandefault false

    The field must have a time.

  • disabledtype booleandefault false

    The field and its clock button can't be used.

  • readOnlytype booleandefault false

    The time can be read and focused but not changed.

  • aria-invalidtype boolean | "false" | "true" | "grammar" | "spelling"

    Read as invalid when that's left out, for a form library that sets the attribute.

  • aria-requiredtype Booleanish

    Read as required when that's left out, for a form library that sets the attribute.

  • aria-readonlytype Booleanish

    Read as readOnly when that's left out, for a form library that sets the attribute.

  • nametype string

    Form field name; the input submits the time as shown.

  • idtype string

    The <input>'s id, for a <label for> or an error summary's link.

  • clockIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon of the button that opens the picker.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density of the field, 0 to -3: each step takes 4px off it (56px at 0, 48px at -2). The picker keeps its size. Left out, the field takes the nearest theme's.

  • reftype Ref<HTMLDivElement>

    The text field's root.

  • inputReftype Ref<HTMLInputElement>

    The <input>.

Events

  • onChangetype ((value: Time | null) => void)

    A time was typed and committed, or picked and confirmed; null when cleared.

  • onOpenChangetype ((open: boolean) => void)

    Called when the picker opens or closes.

Text

  • aria-describedbytype string

    More description for the <input>, after the supporting or error text.

  • aria-detailstype string

    The id of an element with more details about the <input>.

  • labelstype Partial<TimeFieldLabels>

    Words the field and its picker show and announce, with English defaults. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Built to the M3 Expressive time field spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Filled and outlined, on either clock (variant, hourCycle)

    Built

    Variant · Formats

  • Limits and a schedule of times (min, max)

    Built

    Configuration · Schedule

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • TimeField: 40.2 kB

Theming & tokens

It has no tokens of its own: M3 has no time field, so the field and button take the text field's and icon button's tokens, and the docked list the menu's.