Time Field
Enter a time with separate editable segments.
Demos
Size
Variant
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy TimeField.vue and index.ts into app/components/ui/time-field/.
app/components/ui/time-field/TimeField.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | outline, soft, bare | outline |
Models
| Model | Type | Default | Description |
|---|---|---|---|
v-model | TimeValue | undefined | undefined | Accepted clock value. Existing date and zone data are preserved. |
v-model:placeholder | TimeValue | undefined | placeholder or midnight | Base value used before a model exists; accepted edits update it. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | Field id or generated | Id placed on first segment. |
name | string | Field name | Native form name. |
locale | string | "en-US" | Segment order, literals, labels, and default hour cycle. |
dir | "ltr" | "rtl" | "ltr" | Reading direction and horizontal focus movement. |
placeholder | TimeValue | midnight | Base time and value type used before selection. |
minValue | TimeValue | — | Earliest valid clock time. |
maxValue | TimeValue | — | Latest valid clock time. |
isTimeUnavailable | (time) => boolean | — | Application-level unavailable matcher. |
granularity | "hour" | "minute" | "second" | "minute" | Smallest rendered and committed unit. |
hourCycle | 12 | 24 | locale preference | Explicit hour cycle. Use :hour-cycle="24", not a string attribute. |
hideTimeZone | boolean | false | Hides zone label for zoned values. |
step | { hour?, minute?, second? } | each segment 1 | Segment stepping and optional snap interval. |
stepSnapping | boolean | false | Rounds complete values to nearest combined step. |
required | boolean | false | Requires a complete time. |
disabled | boolean | false | Disables all segments and native submission. |
readOnly | boolean | false | Allows focus but blocks edits. |
invalid | boolean | false | Forces invalid presentation. |
selectOnFocus | boolean | true | Selects segment text on focus. |
autoAdvance | boolean | true | Moves focus after two digits. |
ariaLabel | string | "Time" | Root label when no labelled-by relation exists. |
ariaLabelledby | string | Field label id | Explicit label relation. |
ariaDescribedby | string | Field description/error ids | Explicit description relation. |
ui | TimeFieldUi | — | Classes for generated parts. |
Slots
| Slot | Props | Description |
|---|---|---|
literal | value | Locale separator content. |
day-period | value, label, toggle | AM/PM control content and event-safe toggle action. |
time-zone | value | Zone identifier content. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | TimeValue | undefined | Fires after accepted value changes. |
update:placeholder | TimeValue | undefined | Fires when accepted interaction updates placeholder. |
value-change | (value, details) | Fires before model mutation. details.cancel() rejects it. |
value-commit | (value, details) | Fires after complete input, keyboard, paste, day-period, blur, or clear commit. |
Keyboard
| Key | Behavior |
|---|---|
| Number keys | Replaces selected segment text. Complete segments update model. |
ArrowUp / ArrowDown | Steps focused segment, wrapping at boundaries. |
PageUp / PageDown | Steps focused segment by ten increments. |
Home / End | Sets segment minimum or maximum. |
ArrowLeft / ArrowRight | Moves between segments and day period, reversed in RTL. |
Backspace | Clears text; when empty, moves to previous segment. |
A / P | Sets AM or PM while day period is focused. |
| Paste | Distributes colon- or space-separated time parts. |
Each numeric segment uses role="spinbutton" with value bounds. Native inputs and button semantics provide keyboard, mouse, touch, and screen-reader behavior.