Skip to content

TimePicker ​

TimePicker is a time-only field built on reka-ui's popover — the time section of DatePicker's datetime mode, standalone. It emits an HH:MM string, localizes its display and labels through Intl, and each text label can be overridden per instance.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { TimePicker } from '@myghf/ui'

const appointment = ref<string | null>(null)
</script>

<template>
  <TimePicker v-model="appointment" />
</template>

Examples ​

Basic ​

The trigger shows the localized time, or the placeholder while empty. Selecting an hour and minute and pressing Apply commits the value and closes the popover; a Clear action emits null.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { TimePicker } from '@myghf/ui'

const appointment = ref<string | null>('09:30')
</script>

<template>
  <div class="grid max-w-xs gap-4">
    <div class="grid gap-1.5">
      <label class="text-sm font-medium text-foreground" for="demo-time">Appointment time</label>
      <TimePicker input-id="demo-time" v-model="appointment" />
    </div>

    <TimePicker :model-value="null" placeholder="Disabled" disabled />
  </div>
</template>

12-hour format and minute steps ​

hourFormat="12" renders an AM/PM control and formats the trigger accordingly. minuteStep controls the minute interval; it is clamped to 1–30.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { TimePicker } from '@myghf/ui'

const visit = ref<string | null>(null)
const shift = ref<string | null>('14:00')
</script>

<template>
  <div class="grid max-w-sm gap-4">
    <TimePicker v-model="visit" hour-format="12" :minute-step="15" locale="en-US" placeholder="Visit time" />

    <TimePicker v-model="shift" :minute-step="30" placeholder="Shift start (24-hour)" />
  </div>
</template>

Props ​

PropTypeDefaultDescription
modelValuestring | null—Selected value as an HH:MM string, or null when empty.
placeholderstring—Trigger text while empty. Deprecated — prefer labels.placeholder; a labels.placeholder value wins over it.
disabledbooleanfalseDisables the trigger.
invalidbooleanfalseApplies the error border. Falls through to the FormField context when omitted. The trigger is a button, so aria-invalid is not set — the aria-describedby association carries the message.
size'sm' | 'default''default'Trigger height.
inputIdstring—Applied to the trigger button so an external <label for> matches.
hourFormat'12' | '24''24'Time format. '12' also renders an AM/PM control.
minuteStepnumber1Minute interval; clamped to 1–30.
localestringruntime localeBCP-47 locale for time formatting and label defaults. Resolved from Intl.DateTimeFormat at setup, falling back to 'en'.
labelsPartial<TimeLabels>—Per-instance text overrides; merged over the locale defaults.
defaultOpenbooleanfalseOpens the popover on mount. Useful for demos and tests.

labels keys ​

labels accepts any subset of: placeholder, clear, apply, time, hour, minute, am, pm. Built-in translations ship for en, fr, es, de, and ar; other locales fall back to English.

Events ​

EventPayloadDescription
update:modelValuestring | nullEmitted when Apply or Clear is pressed. Apply emits the HH:MM string; Clear emits null.

Slots ​

Every label has a matching slot, each taking no props. A non-empty slot's text wins over both labels and the locale default:

SlotDescription
label-placeholderTrigger text while empty.
label-clearClear action text.
label-applyApply action text.
label-timeAccessible name of the time group and the meridiem select.
label-hourAccessible name of the hour select.
label-minuteAccessible name of the minute select.
label-am / label-pmAM / PM option text (hourFormat="12").

Exposed methods ​

MethodDescription
focus()Focuses the trigger button.

Accessibility ​

  • The trigger is a real <button> with popup semantics from reka-ui (aria-haspopup, aria-expanded); the popover manages focus and closes on Esc.
  • The hour, minute, and meridiem selects are labelled from hour / minute / time, and grouped under a role="group" named from time.
  • invalid only changes colour; it does not set aria-invalid. Add it to the trigger via a fall-through attribute if needed.
  • For an external <label for>, pass inputId to match the label's for (the trigger is a button; associating via aria-labelledby is also acceptable).

Dark mode & RTL ​

  • The popover and trigger use semantic tokens (bg-surface, text-foreground, border-border, shadow-popover), so both themes stay legible.
  • The selects and buttons are direction-neutral, so the control works under RTL without adjustment.

Released under the MIT License.