Time input
VTimeInput offers typed time entry, a clock picker or a searchable list. The model always uses 24-hour HH:mm values.
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const time = ref<string | null>(null)
</script>
<template>
<VTimeInput v-model="time" label="Start time" />
</template>Examples
Label, hint and icon
Name the field with label and add help text with hint.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
import { expand_more as expandMore, search } from 'vectis-ui/icons'
const start = ref<string | null>('09:15')
const meeting = ref<string | null>(null)
</script>
<template>
<div class="column">
<VTimeInput
v-model="start"
label="Start time"
hint="Type it or pick it from the clock"
show-picker
/>
<VTimeInput
v-model="meeting"
label="Meeting"
hint="The glyph that opens the clock is yours to choose"
mode="picker"
:picker-icon="expandMore"
/>
<VTimeInput
v-model="start"
label="Filter by time"
hint="An icon at the start, a spinner at the end while something loads"
:icon-start="search"
loading
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Sizes
size sets the field size.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const rows = ref(
(['sm', 'md', 'lg'] as const).map((size) => ({
key: size,
size,
label: size,
time: '09:15' as string | null,
})),
)
</script>
<template>
<div class="column">
<VTimeInput
v-for="row in rows"
:key="row.key"
v-model="row.time"
:size="row.size"
:label="row.label"
show-picker
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Modes
input allows typing, with an optional clock through showPicker. picker uses the clock alone. list offers searchable time options.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const typed = ref<string | null>('09:15')
const withPicker = ref<string | null>('09:15')
const readOnly = ref<string | null>('09:15')
const fromList = ref<string | null>('09:30')
</script>
<template>
<div class="column">
<VTimeInput
v-model="typed"
label="Typed, the default"
hint="No icon, no panel: the mask is the whole control"
/>
<VTimeInput
v-model="withPicker"
show-picker
label="Typed, with the clock"
hint="showPicker adds the icon and the panel it opens"
/>
<VTimeInput
v-model="readOnly"
mode="picker"
label="Read-only"
hint="Nothing can be typed, so the clock is the only way in"
/>
<VTimeInput
v-model="fromList"
mode="list"
:minute-step="30"
label="List"
hint="Every half hour, found by typing rather than by scrolling"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Steps
minuteStep sets the clock step and list interval. It does not restrict typed minutes. Choose a larger step to shorten the list.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const appointment = ref<string | null>('14:15')
const slot = ref<string | null>('09:30')
const typed = ref<string | null>('08:00')
</script>
<template>
<div class="column">
<VTimeInput
v-model="appointment"
mode="picker"
:minute-step="15"
label="Quarter hours, on the clock"
hint="The face offers four minutes an hour, and the arrow keys move by the same step"
/>
<VTimeInput
v-model="slot"
mode="list"
:minute-step="30"
label="Half hours, as a list"
hint="The step is what the rows are cut at: 48 of them here rather than 1440"
/>
<VTimeInput
v-model="typed"
show-picker
:minute-step="5"
label="Five minutes, typed"
hint="The mask still takes any time; the step drives the clock and the arrow keys"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>What may be chosen
min, max, allowedHours and allowedMinutes restrict clock and list choices. A typed time outside these limits updates the model but fails native field validation.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const typed = ref<string | null>('09:30')
const listed = ref<string | null>('09:30')
const picked = ref<string | null>('09:30')
</script>
<template>
<div class="column">
<VTimeInput
v-model="typed"
format="24h"
min="09:00"
max="17:00"
label="Typed"
hint="Type 08:00 and leave the field: the value stands and the field turns invalid"
/>
<VTimeInput
v-model="listed"
mode="list"
format="24h"
:minute-step="30"
min="09:00"
max="17:00"
label="List"
hint="The rows outside the bounds are not offered at all"
/>
<VTimeInput
v-model="picked"
mode="picker"
format="24h"
:minute-step="30"
min="09:00"
max="17:00"
label="Clock"
hint="The face prints only the hours it can take"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Clearable
clearable adds a button to reset the time.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const withCross = ref<string | null>('09:15')
const withoutCross = ref<string | null>('09:15')
const inList = ref<string | null>('09:30')
</script>
<template>
<div class="column">
<VTimeInput
v-model="withCross"
clearable
show-picker
label="Clearable"
hint="The cross sits to the left of the clock icon, never in its place"
/>
<VTimeInput
v-model="withoutCross"
show-picker
label="Not clearable, the default"
hint="Emptying the field is then the reader's own business"
/>
<VTimeInput
v-model="inList"
clearable
mode="list"
:minute-step="30"
label="Clearable, as a list"
hint="Here the cross is the combobox's own, chevron included"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>States
readonly prevents all value changes while preserving focus. loading shows a spinner without disabling interaction.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const invalid = ref<string | null>('09:15')
</script>
<template>
<div class="column">
<VTimeInput
v-model="invalid"
invalid
show-picker
label="Invalid"
hint="For a rule the browser cannot check by itself"
/>
<VTimeInput
model-value="09:15"
disabled
show-picker
label="Disabled, with a value"
hint="Greyed through the colour tokens, and the panel can no longer be opened"
/>
<VTimeInput model-value="09:15" disabled mode="picker" label="Disabled, picker only" />
<VTimeInput
model-value="09:15"
readonly
show-picker
clearable
label="Read-only"
hint="No typing, no clock, no clear cross"
/>
<VTimeInput
model-value="09:30"
disabled
mode="list"
:minute-step="30"
label="Disabled, as a list"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Twelve-hour clock
format="12h" displays AM/PM controls. The model remains a 24-hour time.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const typed = ref<string | null>('07:00')
const onTheClock = ref<string | null>('19:00')
const fromList = ref<string | null>('19:30')
</script>
<template>
<div class="column">
<VTimeInput
v-model="typed"
format="12h"
show-picker
label="Typed"
hint="The mask says nothing about the half of the day, so a button in the field does"
/>
<VTimeInput
v-model="onTheClock"
format="12h"
mode="picker"
label="Read-only"
hint="Here the pair belongs to the clock, beside its two large numerals"
/>
<VTimeInput
v-model="fromList"
format="12h"
mode="list"
:minute-step="30"
label="List"
hint="Every row spells its own half of the day, so neither control is needed"
/>
<output class="value" aria-label="The three values held">
{{ typed }}, {{ onTheClock }}, {{ fromList }}
</output>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
.value {
font-family: var(--vectis-text-family-code);
font-size: var(--vectis-text-body-sm-size);
color: var(--vectis-color-text-muted);
}
</style>Localization
locale sets time display conventions. An explicit format overrides its hour cycle.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const locales = ref([
{ tag: 'en-US', label: 'en-US, twelve hours', time: '19:30' },
{ tag: 'en-GB', label: 'en-GB, the same words on a 24-hour clock', time: '19:30' },
{ tag: 'fr-FR', label: 'fr-FR', time: '19:30' },
{ tag: 'ja-JP', label: 'ja-JP', time: '19:30' },
])
const forced = ref<string | null>('19:30')
</script>
<template>
<div class="column">
<VTimeInput
v-for="locale in locales"
:key="locale.tag"
v-model="locale.time"
:locale="locale.tag"
:label="locale.label"
show-picker
/>
<VTimeInput
v-model="forced"
locale="en-US"
format="24h"
show-picker
label="en-US, forced onto a 24-hour clock"
hint="format overrides what the tag would have chosen"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Placement
placement sets the preferred panel position.
<script setup lang="ts">
import { ref } from 'vue'
import { VTimeInput } from 'vectis-ui'
const placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'] as const
const times = ref<Record<string, string | null>>({
'bottom-start': '09:15',
'bottom-end': '09:15',
'top-start': '09:15',
'top-end': '09:15',
})
</script>
<template>
<div class="grid">
<VTimeInput
v-for="placement in placements"
:key="placement"
v-model="times[placement]"
:placement="placement"
:label="placement"
mode="picker"
/>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>API
Props
Events
Slots
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
export type TimePickerAllowed = number[] | ((value: number) => boolean)