Keyboard
An on-screen keyboard laid out like the iPhone’s and the iPad’s. It types into the focused field, with shift, symbol layers and number keypads.
Usage
import { Keyboard } from 'nyctoui/keyboard'
<Input inputMode="none" aria-label="Message" />
<Keyboard />The keyboard behaves like the system one: it types into whichever input or textarea has focus, at the caret, without taking focus away. A controlled field updates through its own onChange, and maxLength, readOnly and disabled are respected.
The layouts follow the iPhone and the iPad; the look is NyctoUI’s. Each key is a Button with the tinted fill on a card surface, and presses show at once, as menu rows do.
Give the field inputMode="none" so a phone does not open its own keyboard over this one. Use text inputs: a type="number" input clears values like “1.” while they are typed.
Return reads the field’s enterKeyHint, as iOS does: “go”, “search”, “send”, “next” or “done” replace the return glyph and fill the key. By default return adds a line in a textarea and submits the form around an input.
Good for
- A kiosk or a point-of-sale screen with no physical keyboard.
- A PIN or amount entry screen, using the number keypad.
- Showing a mobile app’s typing flow inside a Phone frame on a landing page.
- A tablet check-in app where the system keyboard would cover the form.
Examples
In a drawer
A bottom Drawer with the keyboard under its field makes a phone-style editing sheet. Focus goes to the field through initialFocus, “done” saves and closes, and the iPad keyboard’s hide key closes too. Typing never starts a swipe; drag the handle or header instead.
On focus
Show the keyboard while a field has focus and hide it on blur. Each field picks its layout, and onKey turns “next” into a move to the following field.
iPhone
Letters, then numbers behind 123 and symbols behind #+=. A space after a number returns to letters. Tap shift for one capital and tap it twice to lock caps. Holding delete repeats it.
Number row
numberRow adds the digits above the letters, as on Android, so codes and IDs need no layer switch. Here caps start locked through defaultShift.
iPad
Wider keys, delete and return on the first two rows, a shift at each end and two-glyph punctuation keys. With onDismiss it gains the hide-keyboard key.
Keypad
layout switches to the phone keypad: number, decimal with a point, or tel with a plus. Here details.cancel() holds the amount to one point and two decimal places.
Physical keys
While the keyboard has focus, keys held on a real keyboard show as pressed on this one, and a held shift capitalizes the labels. Click a keyboard on this page, or tab to it, and type. Keys match by character, so @ lights up on the numbers layer. This only shows presses; with no field focused, nothing is typed.
Keys without a field
With no field to type into, every key still reaches onKey, for a game, a kiosk or a custom editor. Shift is controlled here.
Accessibility
The keyboard is a group labelled “Keyboard”. Each key is a Button with a spoken name such as “shift” or “delete”, and shift reports whether it is on. The keyboard is one tab stop, where it mirrors physical keys. The keys themselves stay out of the tab order, since anyone who reaches them with Tab already has a keyboard, but screen readers and switch access can press them.
Best practices
- Give the field
inputMode="none"so the phone doesn’t open its own keyboard over this one. - Set the field’s
enterKeyHint, so Return reads Go, Search or Send to match what it does. - Use a keypad
layout, such asnumberordecimal, for a PIN or an amount.
- Use it on a normal website people visit on their own phones. Their system keyboard is better.
- Point it at a
type="number"input, which clears values like “1.” while they’re typed. Use a text input.
API reference
Keyboard
The keyboard. Renders a <div> of <button> keys.
| Prop | Type | Default |
|---|---|---|
deviceiPhone or iPad keys. auto picks by width: phone under 600px, tablet above. | 'auto' | 'phone' | 'tablet' | 'auto' |
layoutThe full keyboard, or a phone keypad. | 'text' | 'number' | 'decimal' | 'tel' | 'text' |
numberRowAdds digits above the letters, as on Android. | boolean | false |
shiftShift state. For controlled use. | 'off' | 'on' | 'locked' | — |
defaultShiftStarting shift state. For uncontrolled use. | 'off' | 'on' | 'locked' | 'off' |
onShiftChangeCalled when shift changes. | (shift) => void | — |
targetThe field to type into, focused or not. Defaults to the focused field. | RefObject<HTMLInputElement | HTMLTextAreaElement> | — |
onKeyCalled for each key, named as KeyboardEvent.key names it, before the edit. details.cancel() skips the edit; details.field is the field. | (key: string, details) => void | — |
onDismissAdds a hide-keyboard key to the tablet keyboard. | () => void | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |