Raccourci clavier : Ctrl + K
Commencer

Raccourcis clavier

VHotkeys affiche un raccourci clavier selon les conventions de la plateforme. Activez listen pour émettre un événement lorsqu’il est utilisé.

Utilisation

vue
Raccourci clavier : Ctrl + K
<script setup lang="ts">
import { VHotkeys } from 'vectis-ui'
</script>

<template>
  <VHotkeys keys="mod+k" />
</template>

Exemples

Ce qu'on peut écrire

Écrivez keys sous forme de chaîne séparée par +, sans distinction de casse ni d’espaces. mod désigne Command sur macOS et Ctrl ailleurs ; meta est la touche système littérale. Écrivez la touche plus avec plus. Les valeurs inconnues s’affichent telles quelles.

Vous écrivezmacOSWindows et Linux
modRaccourci clavier : CommandeRaccourci clavier : Ctrl
metacmdcommandwinsuperRaccourci clavier : CommandeRaccourci clavier : Win
ctrlcontrolRaccourci clavier : CtrlRaccourci clavier : Ctrl
altoptionoptRaccourci clavier : AltRaccourci clavier : Alt
shiftRaccourci clavier : MajRaccourci clavier : Maj
enterreturnRaccourci clavier : EntréeRaccourci clavier : Entrée
escescapeRaccourci clavier : ÉchapRaccourci clavier : Échap
spaceRaccourci clavier : EspaceRaccourci clavier : Espace
backspaceRaccourci clavier : Retour arrièreRaccourci clavier : Retour arrière
deletedelRaccourci clavier : SupprRaccourci clavier : Suppr
tabRaccourci clavier : TabRaccourci clavier : Tab
updownleftrightRaccourci clavier : Flèche hautRaccourci clavier : Flèche basRaccourci clavier : Flèche gaucheRaccourci clavier : Flèche droiteRaccourci clavier : Flèche hautRaccourci clavier : Flèche basRaccourci clavier : Flèche gaucheRaccourci clavier : Flèche droite
plusRaccourci clavier : +Raccourci clavier : +
kf5,Raccourci clavier : KRaccourci clavier : F5Raccourci clavier : ,Raccourci clavier : KRaccourci clavier : F5Raccourci clavier : ,

Variantes

variant choisit des touches atténuées, avec bordure ou en relief. Les couleurs héritent du texte environnant.

vue
Raccourci clavier : Ctrl + Maj + P

soft

Raccourci clavier : Ctrl + Maj + P

outline

Raccourci clavier : Ctrl + Maj + P

elevated

<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysVariant } from 'vectis-ui'

const VARIANTS: HotkeysVariant[] = ['soft', 'outline', 'elevated']
</script>

<template>
  <div class="row">
    <div v-for="variant in VARIANTS" :key="variant" class="cell">
      <VHotkeys keys="mod+shift+p" :variant="variant" />
      <VTypography variant="caption" tone="muted">{{ variant }}</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Tailles

Choisissez xs ou sm.

vue
Raccourci clavier : Ctrl + K

xs

Raccourci clavier : Ctrl + K

sm

<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysSize } from 'vectis-ui'

const SIZES: HotkeysSize[] = ['xs', 'sm']
</script>

<template>
  <div class="row">
    <div v-for="size in SIZES" :key="size" class="cell">
      <VHotkeys keys="mod+k" :size="size" variant="outline" />
      <VTypography variant="caption" tone="muted">{{ size }}</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Attaché

attached encadre le raccourci comme une seule touche. Il ne modifie ni son nom accessible ni son comportement.

vue
Raccourci clavier : Ctrl + Maj + K

One cap per key

Raccourci clavier : Ctrl + Maj + K

attached

Raccourci clavier : Ctrl + Maj + K

attached, no separator

<script setup lang="ts">
import { VHotkeys, VTypography } from 'vectis-ui'
</script>

<template>
  <div class="row">
    <div class="cell">
      <VHotkeys keys="mod+shift+k" variant="outline" />
      <VTypography variant="caption" tone="muted">One cap per key</VTypography>
    </div>

    <div class="cell">
      <VHotkeys keys="mod+shift+k" attached variant="outline" />
      <VTypography variant="caption" tone="muted">attached</VTypography>
    </div>

    <div class="cell">
      <VHotkeys keys="mod+shift+k" attached separator="" variant="outline" />
      <VTypography variant="caption" tone="muted">attached, no separator</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Plateforme

platform remplace la détection automatique de la plateforme.

vue

macOS

Raccourci clavier : Commande + KRaccourci clavier : Commande + Maj + EntréeRaccourci clavier : Alt + Retour arrière

Windows

Raccourci clavier : Ctrl + KRaccourci clavier : Win + Maj + EntréeRaccourci clavier : Alt + Retour arrière

Linux

Raccourci clavier : Ctrl + KRaccourci clavier : Super + Maj + EntréeRaccourci clavier : Alt + Retour arrière

Unknown

Raccourci clavier : Ctrl + KRaccourci clavier : Super + Maj + EntréeRaccourci clavier : Alt + Retour arrière
<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysPlatform } from 'vectis-ui'

const PLATFORMS: { value: HotkeysPlatform; label: string }[] = [
  { value: 'mac', label: 'macOS' },
  { value: 'windows', label: 'Windows' },
  { value: 'linux', label: 'Linux' },
  { value: 'other', label: 'Unknown' },
]
</script>

<template>
  <div class="grid">
    <template v-for="platform in PLATFORMS" :key="platform.value">
      <VTypography variant="caption" tone="muted">{{ platform.label }}</VTypography>
      <div class="keys">
        <VHotkeys keys="mod+k" :platform="platform.value" variant="outline" />
        <VHotkeys keys="meta+shift+enter" :platform="platform.value" variant="outline" />
        <VHotkeys keys="alt+backspace" :platform="platform.value" variant="outline" />
      </div>
    </template>
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--vectis-space-3) var(--vectis-space-5);
}
.keys {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Séparateur

separator définit le texte entre les touches. Utilisez une chaîne vide pour juxtaposer les symboles macOS.

vue
Raccourci clavier : Ctrl + Maj + K

The default

Raccourci clavier : Ctrl + Maj + K

Nothing, the macOS convention

Raccourci clavier : Ctrl + Maj + K

A middle dot

Raccourci clavier : Ctrl + Maj + K

A slash

<script setup lang="ts">
import { VHotkeys, VTypography } from 'vectis-ui'

const SEPARATORS = [
  { value: '+', label: 'The default' },
  { value: '', label: 'Nothing, the macOS convention' },
  { value: '·', label: 'A middle dot' },
  { value: '/', label: 'A slash' },
]
</script>

<template>
  <div class="grid">
    <template v-for="separator in SEPARATORS" :key="separator.label">
      <VHotkeys keys="mod+shift+k" :separator="separator.value" variant="outline" />
      <VTypography variant="caption" tone="muted">{{ separator.label }}</VTypography>
    </template>
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--vectis-space-3) var(--vectis-space-5);
  justify-items: start;
}
</style>

Dans le texte et dans les composants

Placez les raccourcis à côté des contrôles, dans les menus ou dans les infobulles.

vue

Press Raccourci clavier : Ctrl + K to open the command palette, then type the first letters of what you are after. Raccourci clavier : Échap puts it away again.

<script setup lang="ts">
import {
  VButton,
  VHotkeys,
  VMenu,
  VMenuItem,
  VMenuSeparator,
  VTooltip,
  VTypography,
} from 'vectis-ui'

const COMMANDS = [
  { label: 'New file', keys: 'mod+n' },
  { label: 'Save', keys: 'mod+s' },
  { label: 'Save as', keys: 'mod+shift+s' },
]
</script>

<template>
  <div class="stack">
    <VTypography class="prose">
      Press <VHotkeys keys="mod+k" /> to open the command palette, then type the first letters of
      what you are after. <VHotkeys keys="esc" /> puts it away again.
    </VTypography>

    <VMenu>
      <template #trigger="{ triggerProps }">
        <VButton v-bind="triggerProps" variant="outline" tone="neutral">File</VButton>
      </template>
      <VMenuItem v-for="command in COMMANDS" :key="command.keys" :label="command.label">
        <template #end><VHotkeys :keys="command.keys" /></template>
      </VMenuItem>
      <VMenuSeparator />
      <VMenuItem label="Settings">
        <template #end><VHotkeys keys="mod+," /></template>
      </VMenuItem>
    </VMenu>

    <VTooltip>
      <template #default="{ triggerProps }">
        <VButton v-bind="triggerProps" variant="outline" tone="neutral">Save</VButton>
      </template>
      <template #content>Save this file <VHotkeys keys="mod+s" size="xs" /></template>
    </VTooltip>

    <VButton variant="outline" tone="neutral" class="search">
      Search the docs
      <VHotkeys keys="mod+k" variant="outline" />
    </VButton>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: var(--vectis-space-5);
}
.prose {
  max-inline-size: 34rem;
  line-height: 1.9;
}
.search {
  inline-size: 18rem;
  justify-content: space-between;
}
</style>

Écoute

listen émet trigger si les touches modificatrices correspondent exactement. allowDefault conserve l’action du navigateur ; allowInInput autorise la détection dans les champs éditables. Échap n’est jamais annulé. La détection utilise le caractère produit : préférez les lettres et touches nommées aux symboles, chiffres AZERTY ou combinaisons Option-lettre sur macOS.

vue

Raccourci clavier : Ctrl + KPress it anywhere on the page. Fired 0 times.

Raccourci clavier : Ctrl + S With allowDefault, the browser still saves the page. Fired 0 times.

Raccourci clavier : Ctrl + JQuiet while a field has the focus: 0

Raccourci clavier : Ctrl + JWith allowInInput, it fires there too: 0

<script setup lang="ts">
import { ref } from 'vue'
import { VHotkeys, VInput, VTypography } from 'vectis-ui'

const opened = ref(0)
const saved = ref(0)
const strict = ref(0)
const permissive = ref(0)
</script>

<template>
  <div class="stack">
    <p class="line">
      <VHotkeys keys="mod+k" variant="outline" listen @trigger="opened++" />
      <VTypography as="span">Press it anywhere on the page. Fired {{ opened }} times.</VTypography>
    </p>

    <!-- allowDefault also lets the browser open its save dialog. -->
    <p class="line">
      <VHotkeys keys="mod+s" variant="outline" listen allow-default @trigger="saved++" />
      <VTypography as="span" tone="muted">
        With allowDefault, the browser still saves the page. Fired {{ saved }} times.
      </VTypography>
    </p>

    <VInput label="Type in here, then press the shortcut below" class="field" />

    <p class="line">
      <VHotkeys keys="mod+j" variant="outline" listen @trigger="strict++" />
      <VTypography as="span">Quiet while a field has the focus: {{ strict }}</VTypography>
    </p>

    <p class="line">
      <VHotkeys keys="mod+j" variant="outline" listen allow-in-input @trigger="permissive++" />
      <VTypography as="span">With allowInInput, it fires there too: {{ permissive }}</VTypography>
    </p>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: var(--vectis-space-4);
}
.line {
  display: flex;
  align-items: center;
  gap: var(--vectis-space-3);
  margin: 0;
}
.field {
  inline-size: 22rem;
}
</style>

API

Props

PropTypeDéfaut
keysstringaucune
Chaîne de raccourci séparée par +. Utilisez mod pour Command/Ctrl et plus pour la touche plus.
variantHotkeysVariant'soft' | 'outline' | 'elevated''soft'
Style des touches : atténué, avec bordure ou en relief.
attachedbooleanfalse
Encadre toute la combinaison comme une seule touche.
sizeHotkeysSize'xs' | 'sm''xs'
Taille du composant.
platformHotkeysPlatform'mac' | 'windows' | 'linux' | 'other'aucune
Plateforme imposée pour l’affichage et la détection du raccourci.
separatorstring'+'
Texte entre les touches. Une chaîne vide conserve uniquement l’espacement.
listenbooleanfalse
Active la détection du raccourci et l’événement trigger.
allowDefaultbooleanfalse
Conserve l’action du navigateur lors de la détection. Échap est toujours conservé.
allowInInputbooleanfalse
Autorise la détection dans les champs éditables.
labelstringaucune
Nom accessible du raccourci. Lecture localisée des touches par défaut.

Événements

ÉvénementType
trigger[event: KeyboardEvent]
Le raccourci a été utilisé avec listen activé. Reçoit l’événement clavier.