# Time field

A typed time in the locale's clock, with minute steps and an optional time zone.

- Family: date
- Import: `import { TimeField } from "@senvenli/react/date";`
- Page: https://design.senvenli.com/docs/components/time-field
- JSON: https://design.senvenli.com/docs/components/time-field.json

## Example: A typed time

The locale's clock: 12-hour with AM and PM in English.

```tsx
import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";

export default function Example() {
  return <TimeField label="Opens at" defaultValue={new Time(9, 0)} />;
}
```

## Examples

### Minute steps and a 24-hour clock

Arrow keys move the minutes a quarter of an hour at a time.

```tsx
import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";

export default function Example() {
  return (
    <TimeField
      label="Delivery cutoff"
      description="Orders placed later ship the next day."
      hourCycle={24}
      minuteStep={15}
      defaultValue={new Time(16, 30)}
      minValue={new Time(12, 0)}
      maxValue={new Time(20, 0)}
    />
  );
}
```

### In another time zone

The zone is named after the time when it differs from the visitor's, so the label appears once the page runs in the browser.

```tsx
import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";

export default function Example() {
  return <TimeField label="Pickup time" description="The store's local time." timeZone="Europe/Lisbon" defaultValue={new Time(10, 0)} />;
}
```

## Guidelines

### When to use it

- Typing a time of day.

### Use something else when

- [radio](https://design.senvenli.com/docs/components/radio.md): Only certain times are available: a card RadioGroup of them (see its time-slots example).

## Accessibility

Keyboard:

- Arrow up / down: Changes the focused part.

Built in:

- Required fields show "Fill in this field."; a partly typed date says what is missing.

You provide:

- A visible label.

## API reference

### TimeField

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| label | `React.ReactNode` |  | yes | Always given; the label sits above the field and names its segments. |
| description | `React.ReactNode` |  | no |  |
| errorMessage | `React.ReactNode` |  | no | What happened and what to do; shown when the field is invalid. |
| isRequired | `boolean` |  | no |  |
| requiredValidation | `RequiredValidation` |  | no | Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract. |
| isOptional | `boolean` |  | no | Shows "(optional)" when most of the form is required. |
| isDisabled | `boolean` |  | no |  |
| isReadOnly | `boolean` |  | no |  |
| isInvalid | `boolean` |  | no | Marks the field invalid from outside (a server error); `errorMessage` says why. |
| id | `string` |  | no | The id of the field's first typed segment (day, or the locale's first part), the element that takes focus : `document.getElementById(id).focus()` puts the user in the field, as a focus-on-error does. The field's group gets an id of its own. Left out, the DOM is as before. |
| name | `string` |  | no | The form field name; the value is submitted as an ISO string. |
| autoFocus | `boolean` |  | no |  |
| onBlur | `(event: FocusEvent<Element, Element>) => void` |  | no |  |
| value | `TimeValue` |  | no | A time, or a zoned date-time when a location's zone travels with it. While the user leaves a time typed in part ("10:––"), the field reports `onChange(null)` and keeps the typed parts on screen, so setting `null` changes nothing: the value already is null. To clear the field (an app's own "Temizle" or form reset), give it a new `key` along with the value: React remounts it empty, or at the value given . |
| defaultValue | `TimeValue` |  | no |  |
| onChange | `(value: TimeValue \| null) => void` |  | no |  |
| hourCycle | `12 \| 24` |  | no | 24-hour in tr and me, 12-hour in en-US; from the locale unless set. |
| granularity | `"hour" \| "minute"` |  | no |  |
| minuteStep | `number` |  | no | Arrow keys step the minutes by this much (15 or 30). |
| timeZone | `string` |  | no | The location's zone (IANA, "Europe/Lisbon"). Named after the time when it differs from the user's. |
| minValue | `TimeValue` |  | no |  |
| maxValue | `TimeValue` |  | no |  |
| validate | `(value: TimeValue \| null) => string \| true \| string[] \| null \| undefined` |  | no |  |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-radius-small`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

- [radio](https://design.senvenli.com/docs/components/radio.md)
- [date-field](https://design.senvenli.com/docs/components/date-field.md)
