On-Screen Keyboard
ProA full keyboard for touch screens with no physical one: a large display, letters, symbols, shift and a space bar, wired to a value you control.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
It types at the end of the value. The display grows with the keyboard and never opens a device keyboard of its own. To drive a field elsewhere on the screen, leave the display out and set readOnly on that field. For digits only, use Keypad.
Anatomy#
import { OnScreenKeyboard, OnScreenKeyboardDisplay } from "@/components/ui/on-screen-keyboard"
<OnScreenKeyboard>
<OnScreenKeyboardDisplay />
</OnScreenKeyboard>Sizes#
md suits a tablet in the hand, lg a till and xl a kiosk. Keys share the width they are given and stay square, so a wider keyboard means bigger targets. In a narrow container they keep the minimum height of their size.
Layouts and languages#
Rows are plain strings, so any layout is one array away. QWERTY_ES ships with the ñ, and the words on the keys come from LabelsProvider.
API reference#
OnScreenKeyboard
The keyboard. Keys type on touch, not on release, leave a short brand afterglow, and never take focus, so any field outside it keeps its focus ring and caret. Holding delete repeats it. Accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The text, controlled. |
| defaultValue | string | "" | The text when uncontrolled. |
| onValueChange | (value: string) => void | - | Called on every key that changes the text. |
| onEnter | (value: string) => void | - | Called by the enter key. |
| letters | string[] | QWERTY | One string per row. QWERTY_ES adds the ñ. |
| symbols | string[] | SYMBOLS | The rows of the second layer. |
| size | "md" | "lg" | "xl" | "lg" | Minimum key height: 44, 56 or 64px. Keys turn square once the width allows it. |
| disabled | boolean | false | Locks every key. |
| enterLabel | ReactNode | - | Names what enter does here, such as Search. Falls back to the enter label. |
| Data attribute | Description |
|---|---|
| data-slot | "on-screen-keyboard", with -row, -key, -shift, -delete, -layer, -space and -enter parts. |
| data-layer | "letters" or "symbols". |
OnScreenKeyboardDisplay
The text being typed, at the scale of the keys, with a clear button. Reads the value and size from the keyboard, follows the end of long text and announces changes. While someone types it holds the focus ring and a steady caret. Accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| placeholder | string | - | Shown while empty, and names the display for screen readers. |
| Data attribute | Description |
|---|---|
| data-slot | "on-screen-keyboard-display", with -caret and -clear parts. |
| data-active | Present while someone is typing, and for two seconds after. |