-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added documentation for simply.keyboard
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# simply.keyboard | ||
|
||
simply.keyboard is a simple library to add keyboard support to your application: | ||
|
||
```javascript | ||
let myKeys = { | ||
default: { | ||
ArrowDown: (e) => { | ||
// handle arrow down | ||
} | ||
} | ||
} | ||
simply.keyboard(myApp, myKeys); | ||
``` | ||
|
||
But generally you won't use this directly, but through simply.app: | ||
|
||
```javascript | ||
var myApp = simply.app({ | ||
keyboard: { | ||
default: { | ||
ArrowDown: (e) => { | ||
|
||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
You can add multiple keyboard definitions: | ||
|
||
```javascript | ||
var counterApp = simply.app({ | ||
keyboard: { | ||
default: { | ||
ArrowDown: (e) => { | ||
|
||
} | ||
}, | ||
alternate: { | ||
ArrowDown: (e) => { | ||
|
||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
The default keyboard is 'default', but you can switch the keyboard by setting this attribute: | ||
|
||
```html | ||
<div data-simply-keyboard="alternate"> | ||
<input type="text" name="example"> | ||
</div> | ||
``` | ||
|
||
Whenever a keyboard `keydown` is fired, simply.keyboard will look for the closest parent with a `data-simply-keyboard` attribute. If found, it will use that keyboard definition. If not found, it will use `default`. | ||
|
||
The `keydown` event is only handled if the activeElement (the element that has focus) is inside the application container. See `simply.app` for more on that. | ||
|