Preview
Type four words. The next key lights up, and your real keyboard works too, even without Khmer installed.
hello1 of 4
សួស្តី
Click here, then type on your keyboard
Install
pnpx sothearo add khmer-keyboard
It checks whether you use Vue, Nuxt or React, and adds only the files you need to your components folder, in khmer-keyboard/. They're yours to change.
Usage
Bind the text with v-model, and pass the word to type as target. Its next key lights up, Shift too when it's needed, and delete after a mistake. In Nuxt it's auto-imported, so you can skip the import.
<script setup lang="ts">
import { ref } from "vue";
import KhmerKeyboard from "@/components/khmer-keyboard/KhmerKeyboard.vue";
const text = ref("");
</script>
<template>
<KhmerKeyboard v-model="text" target="សួស្តី" latin />
</template>
Typing test
check compares what was typed with the target. It tells you if the text is right so far, if it's done, and which key comes next. Turn on capture while your test has focus, and real keys type Khmer even on a computer without a Khmer keyboard.
import { check } from "@/components/khmer-keyboard/core";
check("សួស្តី", "សួ");
// { correct: true, done: false, next: { key: KeyS, shift: false } }
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
v-model | string | "" | The typed text. Keys add to it, delete removes the last character. |
target | string | The word to type. The key to press next lights up. | |
latin | boolean | false | Shows the Latin letter in the corner of each key. |
capture | boolean | false | Real keys type Khmer into v-model. Fields and shortcuts are left alone. |
Events and slots
| Name | Gives you | When |
|---|---|---|
@press | text | A key types something. |
@backspace | Delete is pressed. | |
#key | item, text, hinted, pressed | Replace what each key shows. |
Customise
Every colour comes from the text colour, so the keyboard fits light and dark themes on its own. Change it with CSS variables, and style states with data attributes.
[data-khmer-keyboard] {
--khmer-keyboard-font: "Kantumruy Pro", sans-serif;
--khmer-keyboard-gap: 6px;
--khmer-keyboard-max-width: 560px;
}
[data-khmer-keyboard] [data-hint] {
--khmer-keyboard-ink: #2f6fed;
}
Keys carry data-kind, data-hint and data-pressed, so you can target one kind of key or one state without new props.
Accessibility
- Every key is a real button with a label, so screen readers say the character it types.
- Keys don't take focus when clicked, so the text field keeps it.
- Without
capture, your physical keys only light up. The keyboard never changes what they type. - Motion turns off when the system asks for reduced motion.