Raccourci clavier : Ctrl + K
Commencer

Champ d'heure

VTimeInput permet de saisir une heure, de la choisir sur une horloge ou dans une liste filtrable. Le modèle utilise toujours le format sur 24 heures HH:mm.

Utilisation

vue
<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>

Exemples

Libellé, indication et icône

Nommez le champ avec label et ajoutez une aide avec hint.

vue

Type it or pick it from the clock

The glyph that opens the clock is yours to choose

Chargement…

An icon at the start, a spinner at the end while something loads

<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>

Tailles

size définit la taille du champ.

vue
<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 permet la saisie, avec une horloge facultative via showPicker. picker utilise uniquement l’horloge. list propose une liste d’heures filtrable.

vue

No icon, no panel: the mask is the whole control

showPicker adds the icon and the panel it opens

Nothing can be typed, so the clock is the only way in

Every half hour, found by typing rather than by scrolling

<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>

Pas

minuteStep définit le pas de l’horloge et l’intervalle de la liste. Il ne limite pas les minutes saisies. Un pas plus grand réduit la longueur de la liste.

vue

The face offers four minutes an hour, and the arrow keys move by the same step

The step is what the rows are cut at: 48 of them here rather than 1440

The mask still takes any time; the step drives the clock and the arrow keys

<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>

Ce que l’on peut choisir

min, max, allowedHours et allowedMinutes limitent les choix de l’horloge et de la liste. Une heure saisie hors de ces limites modifie le modèle, mais échoue à la validation native du champ.

vue

Type 08:00 and leave the field: the value stands and the field turns invalid

The rows outside the bounds are not offered at all

The face prints only the hours it can take

<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>

Effaçable

clearable ajoute un bouton pour effacer l’heure.

vue

The cross sits to the left of the clock icon, never in its place

Emptying the field is then the reader's own business

Here the cross is the combobox's own, chevron included

<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>

États

readonly empêche toute modification de la valeur et conserve le focus. loading affiche un indicateur sans désactiver les interactions.

vue

For a rule the browser cannot check by itself

Greyed through the colour tokens, and the panel can no longer be opened

No typing, no clock, no clear cross

<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>

Horloge de douze heures

format="12h" affiche des contrôles AM/PM. Le modèle reste une heure sur 24 heures.

vue

The mask says nothing about the half of the day, so a button in the field does

Here the pair belongs to the clock, beside its two large numerals

Every row spells its own half of the day, so neither control is needed

07:00, 19:00, 19:30
<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>

Localisation

locale définit les conventions d’affichage. Un format explicite remplace son cycle horaire.

vue

format overrides what the tag would have chosen

<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>

Positionnement

placement définit la position souhaitée du panneau.

vue
<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

PropTypeDéfaut
formatTimePickerFormat'12h' | '24h'aucune
Affichage sur 12 ou 24 heures. Dépend de la locale par défaut ; le modèle utilise toujours 24 heures.
modeTimeInputMode'picker' | 'input' | 'list''input'
Saisie, sélection sur horloge ou liste d’heures filtrable.
showPickerbooleanfalse
Ajoute une horloge au mode saisie. Le mode horloge l’inclut toujours ; le mode liste l’ignore.
minuteStepnumber1
Pas de l’horloge et intervalle de la liste en minutes. Ne limite pas les valeurs saisies.
minstringaucune
Première heure autorisée, incluse, au format HH:mm.
maxstringaucune
Dernière heure autorisée, incluse, au format HH:mm.
allowedHoursTimePickerAllowedaucune
Heures autorisées : tableau ou prédicat recevant une valeur sur 24 heures.
allowedMinutesTimePickerAllowedaucune
Minutes autorisées : tableau ou prédicat.
localestringaucune
Locale BCP 47 pour l’affichage des heures. Remplace la locale globale ; format est prioritaire.
labelstringaucune
Libellé visible. Sans nom visible, fournissez aria-label ou aria-labelledby.
hintstringaucune
Texte d’aide lié par aria-describedby.
errorstringaucune
Message d’erreur affiché à la place de l’aide. Pose aria-invalid, est lié par aria-describedby et est annoncé quand il apparaît.
requiredbooleanfalse
Ajoute un astérisque après le libellé et transmet required au champ.
hideLabelbooleanfalse
Masque le libellé visuellement tout en le gardant comme nom accessible.
labelPositionFieldLabelPosition'top' | 'start''top'
Place le libellé au-dessus du champ ou à côté.
placeholderstringaucune
Texte indicatif lorsque le champ est vide.
sizeTimeInputSize'sm' | 'md' | 'lg''md'
Taille du composant.
disabledbooleanfalse
Désactive les interactions.
readonlybooleanfalse
Empêche la saisie, la sélection, le changement AM/PM et l’effacement. Conserve le focus.
invalidbooleanfalse
Définit aria-invalid et le style d’erreur. Ne bloque pas à lui seul l’envoi du formulaire.
iconStartIconSourceaucune
Icône de début. Un écouteur @click:icon-start en fait un bouton ; fournissez iconStartLabel.
iconStartLabelstringaucune
Nom accessible du bouton d’icône de début.
pickerLabelstringaucune
Nom accessible du bouton horloge. Utilise le dictionnaire de la bibliothèque par défaut.
loadingbooleanfalse
Remplace l’icône horloge par un indicateur sans désactiver le champ.
loadingTextstringaucune
Texte de chargement et nom accessible de l’indicateur. Utilise le dictionnaire de la bibliothèque par défaut.
clearablebooleanfalse
Ajoute un bouton pour effacer la valeur.
clearLabelstringaucune
Nom accessible du bouton d’effacement. Utilise le dictionnaire de la bibliothèque par défaut.
pickerIconIconSourceschedule
Icône du bouton horloge. Sans effet en mode liste.
placementTimeInputPlacement'bottom' | 'bottom-start' | 'bottom-end' | 'top' | 'top-start' | 'top-end''bottom-start'
Position souhaitée du panneau par rapport au champ.
v-modelstring | nullnull
Heure sur 24 heures au format HH:mm, ou null.

Événements

ÉvénementType
click:icon-start[event: MouseEvent]
Le bouton de l’icône de début a été activé.
clear[]
L’heure a été effacée ; le modèle est déjà réinitialisé.

Slots

SlotType
start{}
Contenu après iconStart.
value-end{}
Contenu avant les boutons d’effacement et de sélection.
footerTimeInputFooterSlotProps
Remplace les boutons Annuler et OK de l’horloge. Appelez confirm pour valider le brouillon ou cancel / close pour l’annuler. Absent en mode liste.

Types

Types utilisés dans les tables d’API. Importez les types exportés depuis 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 interface TimeInputFooterSlotProps {
  confirm: () => void
  cancel: () => void
  close: () => void
}
export type TimePickerAllowed = number[] | ((value: number) => boolean)