Skip to content

Time field

Clock entry in the UI's locale, for the hours that are not attached to a day. A native time input is drawn in the BROWSER's language, so a German page in an English-US Chrome asks for AM/PM.

View as Markdown

Preview

Opening time Reads and writes HH:mm; the locale decides whether that is 14:30 or 2:30 PM.

<div class="nx-field nx-timefield">
  <label class="nx-field__label" for="open1">Öffnet</label>
  <input id="open1" class="nx-field__input nx-timefield__input"
      value="09:00" inputmode="numeric" placeholder="09:00">
</div>

Variants

A pair, in a row

Two of them are an opening and a closing; keep them in one row and let the field be as wide as a time.

<div style="display:flex;gap:16px">
  <div class="nx-field nx-timefield">
    <label class="nx-field__label" for="open2">Öffnet</label>
    <input id="open2" class="nx-field__input nx-timefield__input"
        value="09:00" inputmode="numeric">
  </div>
  <div class="nx-field nx-timefield">
    <label class="nx-field__label" for="close2">Schließt</label>
    <input id="close2" class="nx-field__input nx-timefield__input"
        value="20:00" inputmode="numeric">
  </div>
</div>

API

React props (NxKit)

React (NxKit) props
PropTypeDefaultRequiredDescription
labelstring—RequiredVisible label, tied to the input.
valuestring—Required"" or "HH:mm" — what a native time input would have submitted.
onChange(value: string) => void—RequiredCalled with HH:mm, or "" when cleared — never with a half-typed time.
localestringruntime defaultBCP-47 tag of the UI. de reads 14:30 where en-US reads 2:30 PM.
namestringundefinedEmits a hidden input, so the field works in a plain FormData submit.
requiredbooleanfalseLands on the visible input. Still validate on the server.
hideLabelbooleanfalseKeeps the label for screen readers and takes it off the screen.
disabledbooleanfalseDisables the input.
hintReact.ReactNodeundefinedHelp text under the control.
errorReact.ReactNodeundefinedError text; also sets aria-invalid.

Classes

Framework-agnostic classes
ClassDescription
.nx-timefieldWrapper, used with .nx-field
.nx-timefield__inputThe input, as wide as a time and tabular-nums

States

error

Diese Uhrzeit gibt es nicht.

disabled

Accessibility

  • The label is a real <label> tied by htmlFor; hideLabel moves it off screen with .nx-sr-only rather than removing it.
  • Typing is never corrected mid-keystroke: the box that has focus is left alone until blur.

Do / Don’t

  • Do: Use it for an hour with no day — opening times, a send time, a shift.Don't pair it with a separate date field; NxDateField withTime keeps the two halves one value.
  • Do: Let it keep its width: a time is eight characters.Don't stretch it across the form; it reads as a text field then.

View in spec