Reka UI logoReka
backdrop
Components

Time Field

Enables users to input specific times within a designated field.
––
––
AM

Features

  • Full keyboard navigation
  • Can be controlled or uncontrolled
  • Focus is fully managed
  • Localization support
  • Highly composable
  • Accessible by default

Preface

The component works with the Temporal API: its values are Temporal.PlainTime, Temporal.PlainDateTime or Temporal.ZonedDateTime. Reka UI does not bundle a Temporal implementation, so on runtimes without native Temporal your app loads a polyfill. See Dates & Times for the setup and how the components treat calendars and time zones.

Installation

On runtimes without native Temporal, install a polyfill and load it once, before the app mounts.

sh
$ npm add temporal-polyfill-lite
ts
// main.ts
import { install } from 'temporal-polyfill-lite/shim'

install(false) // keeps the native Temporal when the browser has one

Install the component from your command line.

sh
$ npm add reka-ui

Anatomy

Import all parts and piece them together.

vue
<script setup>
import {
  TimeFieldInput,
  TimeFieldRoot,
} from 'reka-ui'
</script>

<template>
  <TimeFieldRoot>
    <TimeFieldInput />
  </TimeFieldRoot>
</template>

API Reference

Root

Contains all the parts of a time field

Data AttributeValue
[data-readonly]Present when readonly
[data-disabled]Present when disabled
[data-invalid]Present when invalid

Input

Contains the time field segments

Data AttributeValue
[data-disabled]Present when disabled
[data-invalid]Present when invalid
[data-placeholder]Present when no value is set

Accessibility

Keyboard Interactions

KeyDescription
Tab
When focus moves onto the time field, focuses the first segment.
ArrowLeftArrowRight
Navigates between the time field segments.
ArrowUpArrowDown
Increments/changes the value of the segment.
0-9
When the focus is on a numeric TimeFieldInput, it types in the number and focuses the next segment if the next input would result in an invalid value.
Backspace
Deletes a digit from the focused numeric segments.
AP
When the focus is on the day period, it sets it to AM or PM.

In a right-to-left layout (dir="rtl" on TimeFieldRoot, or on a ConfigProvider), ArrowLeft moves to the next segment and ArrowRight to the previous one. See Internationalization.

Headless composable

useTimeField owns the value, the placeholder and the segments: segments, setModelValue(), isInvalid (with minValue, maxValue and isTimeUnavailable), the root part surface and createInputSurface(part) for each segment. It registers watchers and collects the segment elements on mount, so call it inside setup(). The composable is experimental; see Headless composables.