Time Range Field
Enter start and end times.
Demos
Size
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 TimeRangeField.vue and index.ts into app/components/ui/time-range-field/. Also copy the required components: Time Field.
app/components/ui/time-range-field/TimeRangeField.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 |
Models
| Model | Type | Default | Description |
|---|---|---|---|
v-model | TimeRange | {} | Optional start and end TimeValues. Partial segment text stays internal. |
v-model:placeholder | TimeValue | undefined | placeholder | Shared base value for both endpoints. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | Field id or generated | Start field id; end adds -end. |
name | string | Field name | Derives .start and .end form names. |
startName / endName | string | derived | Explicit native form names. |
locale | string | "en-US" | Segment order, labels, and default hour cycle. |
dir | "ltr" | "rtl" | "ltr" | Reading direction. |
placeholder | TimeValue | midnight | Shared base time and value type. |
minValue / maxValue | TimeValue | — | Endpoint boundaries. |
isTimeUnavailable | (time) => boolean | — | Endpoint application constraint. |
granularity | "hour" | "minute" | "second" | "minute" | Smallest endpoint unit. |
hourCycle | 12 | 24 | locale preference | Explicit hour cycle. |
hideTimeZone | boolean | false | Hides zoned endpoint labels. |
step | { hour?, minute?, second? } | each 1 | Endpoint keyboard step. |
stepSnapping | boolean | false | Snaps complete endpoint values. |
required | boolean | false | Requires both endpoints. |
disabled | boolean | false | Disables endpoints and form submission. |
readOnly | boolean | false | Allows focus but blocks edits. |
invalid | boolean | false | Forces invalid presentation. |
selectOnFocus | boolean | true | Selects focused segment text. |
autoAdvance | boolean | true | Advances after two digits. |
startLabel | string | "Start time" | Accessible start label. |
endLabel | string | "End time" | Accessible end label. |
ariaLabel | string | "Time range" | Root label without Field label relation. |
ariaLabelledby / ariaDescribedby | string | Field relations | Explicit ARIA relationships. |
ui | TimeRangeFieldUi | — | Classes for range and endpoint parts. |
Slots
| Slot | Props | Description |
|---|---|---|
start-literal / end-literal | value | Endpoint locale separators. |
start-day-period / end-day-period | value, label, toggle | Endpoint AM/PM content. |
start-time-zone / end-time-zone | value | Endpoint zone content. |
separator | — | Visual separator; hidden from assistive technology. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | TimeRange | Fires after accepted endpoint changes. |
update:placeholder | TimeValue | undefined | Fires after accepted placeholder changes. |
value-change | (range, details) | Cancelable proposed range update. |
value-commit | (range, details) | Accepted endpoint commit with prefixed reason. |
Keyboard
Each endpoint uses Time Field keyboard behavior:
| Key | Behavior |
|---|---|
| Number keys / paste | Edits focused endpoint segment. |
ArrowUp / ArrowDown | Steps segment. |
PageUp / PageDown | Steps by ten increments. |
Home / End | Sets segment boundary. |
ArrowLeft / ArrowRight | Moves within current endpoint. |
Tab / Shift + Tab | Uses native order across both endpoints and surrounding controls. |
A / P | Sets focused endpoint day period. |
Mouse and touch edit the native inputs and day-period buttons. The component does not require hover input.