From 7c292d04bfccbd7b52f08e08a4a701701689550b Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Mon, 30 Apr 2018 11:05:55 -0400 Subject: [PATCH] Adding inputName, setOptions, Use-cases documentation --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index ca4bbddd..7d0fb5e3 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,14 @@ debug: false newLineOnEnter: false ``` +### inputName + +> Allows you to use a single simple-keyboard instance for several inputs. + +```js +inputName: "default" +``` + ## Methods simple-keyboard has a few methods you can use to further control it's behavior. @@ -212,6 +220,49 @@ let input = keyboard.getInput(); keyboard.setInput("Hello World!"); ``` +### setOptions + +> Set new option or modify existing ones after initialization. The changes are applied immediately. + +```js +keyboard.setOptions({ + theme: "my-custom-theme" +}); +``` + +## Use-cases + +### Using several inputs + +Set the *[inputName](#inputname)* option for each input you want to handle with simple-keyboard. + +For example: +```html + + +``` + +```js + // Initialize simple-keyboard as usual + var keyboard = new Keyboard({ + onChange: input => console.log(input), + onKeyPress: button => console.log(button), + }); + + // Add an event listener for the inputs to be tracked + document.querySelectorAll('.input') + .forEach(input => input.addEventListener('focus', onInputFocus)); + + // Set the inputName option on the fly ! + function onInputFocus(event){ + keyboard.setOptions({ + inputName: event.target.id + }); + } +``` + +[Using several inputs](#using-several-inputs) + ## Demo