react-simple-keyboard
React Virtual Keyboard - Customizable, responsive and lightweight
Installation
npm install react-simple-keyboard --save
Usage
Need a more extensive example? Click here.
Options
You can customize the Keyboard by passing options (props) to it.
Here are the available options (the code examples are the defaults):
layout
Modify the keyboard layout
layoutName
Specifies which layout should be used.
display
Replaces variable buttons (such as
{bksp}
) with a human-friendly name (e.g.: "delete").
theme
A prop to add your own css classes. You can add multiple classes separated by a space.
debug
Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.
newLineOnEnter
Specifies whether clicking the "ENTER" button will input a newline (
\n
) or not.
inputName
Allows you to use a single simple-keyboard instance for several inputs.
onKeyPress
Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
onChange
Executes the callback function on input change. Returns the current input's string.
onChangeAll
Executes the callback function on input change. Returns the input object with all defined inputs. This is useful if you're handling several inputs with simple-keyboard, as specified in the "Using several inputs" guide.
Methods
simple-keyboard has a few methods you can use to further control it's behavior.
To access these functions, you need a ref
of the simple-keyboard component, like so:
clearInput
Clear the keyboard's input.
getInput
Get the keyboard's input (You can also get it from the onChange prop).
setInput
Set the keyboard's input. Useful if you want the keybord to initialize with a default value, for example.
It returns a promise, so if you want to run something after it's applied, call it as so:
Use-cases
Using several inputs
Set the inputName option for each input you want to handle with simple-keyboard.
For example: