Keyboard shortcuts - litejs/ui GitHub Wiki
Keyboard shortcuts in views (preferred)
Use @kb in view templates to bind keyboard shortcuts.
Shortcuts are automatically added when the view opens and removed when it closes.
%view home #public
@kb {h: "home", u: "users", "ctrl+s": save}
...
String values navigate to the view, function values are called directly.
Keyboard shortcuts in JavaScript
El.addKb and El.rmKb can be used directly,
but require manual cleanup — prefer the template version above.
var goHome = $ui.show.bind(null, "home")
, keyboardShortcuts = {
h: goHome,
"shift+h": goHome,
"ctrl+h": goHome,
"alt+h": goHome,
"mod+h": goHome, // `command+h` on Mac and `ctrl+h` on PC
bubble: true, // bubble up to previous map if key not found (default: false)
input: true // capture keys in input/textareas (default: false)
}
// bind
El.addKb(keyboardShortcuts)
// unbind
El.rmKb(keyboardShortcuts)
Modifier keys
| Modifier | Key |
|---|---|
shift+ |
Shift |
ctrl+ |
Control |
alt+ |
Alt/Option |
mod+ |
Command on Mac, Control on PC |
Options
| Option | Default | Effect |
|---|---|---|
bubble |
false |
Bubble up to previous keyboard map if key not found |
input |
false |
Capture keys even when focus is in input/textarea |