Skip to content

feat: Keyboard bindings #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
510da11
Allow top nav to receive keyboard focus
jhildenbiddle Oct 16, 2023
8699c51
Add key binding listener and default config
jhildenbiddle Oct 16, 2023
bd3ca7c
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Oct 25, 2023
4c121d5
Revert "Allow top nav to receive keyboard focus"
jhildenbiddle Oct 25, 2023
7200ee0
Update key binding config format and defaults
jhildenbiddle Oct 25, 2023
608512e
Add key binding for search plugin
jhildenbiddle Oct 25, 2023
e0e4ac8
Add keyBinding documentation
jhildenbiddle Oct 25, 2023
ae00f1c
Add select elements to list of ignored elements
jhildenbiddle Oct 26, 2023
00875f1
Add key binding tests
jhildenbiddle Oct 26, 2023
0963ea6
Update playwright dependency
jhildenbiddle Oct 26, 2023
dc89062
Update playwright dependency lock
jhildenbiddle Oct 26, 2023
02e4864
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Nov 16, 2023
6617604
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Nov 17, 2023
01fb56f
Remove focus content binding
jhildenbiddle Nov 23, 2023
2eabc5f
Update ignore keyboard binding test
jhildenbiddle Nov 23, 2023
095b1a6
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Nov 29, 2023
810f3d3
Merge branch '2278-keybindings' of https://github.com/docsifyjs/docsi…
jhildenbiddle Nov 29, 2023
4615463
Fix search focus with hidden sidebar
jhildenbiddle Nov 29, 2023
0abf5e1
Add search keybinding icon and title hint
jhildenbiddle Nov 29, 2023
fa90428
Add sidebar toggle keybinding title hint
jhildenbiddle Nov 29, 2023
4461aca
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Nov 30, 2023
d63f519
Merge branch 'develop' into 2278-keybindings
sy-records Nov 30, 2023
4c574fe
Merge branch 'develop' into 2278-keybindings
jhildenbiddle Nov 30, 2023
929eb58
Sort keybindings (modifiers first)
jhildenbiddle Nov 30, 2023
26aa539
Add aria-keyshortcuts attribute
jhildenbiddle Nov 30, 2023
b360221
Remove keyCode check (deprecated)
jhildenbiddle Nov 30, 2023
1164356
Update documentation
jhildenbiddle Nov 30, 2023
9d90e1f
Update docs
jhildenbiddle Nov 30, 2023
ac9b8ed
Update aria-keyshortcuts
jhildenbiddle Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,54 @@ window.$docsify = {
};
```

## keyBindings

- Type: `Boolean|Object`
- Default: `Object`
- <kbd>\\</kbd> Toggle the sidebar menu
- <kbd>/</kbd> Focus on [search](plugins#full-text-search) field. Also supports <kbd>alt</kbd>&nbsp;/&nbsp;<kbd>ctrl</kbd>&nbsp;+&nbsp;<kbd>k</kbd>.

Binds key combination(s) to a custom callback function.

Key `bindings` are defined as case insensitive string values separated by `+`. Modifier key values include `alt`, `ctrl`, `meta`, and `shift`. Non-modifier key values should match the keyboard event's [key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) or [code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code) value.

The `callback` function receive a [keydown event](https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event) as an argument.

!> Let site visitors know your custom key bindings are available! If a binding is associated with a DOM element, consider inserting a `<kbd>` element as a visual cue (e.g., <kbd>alt</kbd> + <kbd>a</kbd>) or adding [title](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title) and [aria-keyshortcuts](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-keyshortcuts) attributes for hover/focus hints.

```js
window.$docsify = {
keyBindings: {
// Custom key binding
myCustomBinding: {
bindings: ['alt+a', 'shift+a'],
callback(event) {
alert('Hello, World!');
},
},
},
};
```

Key bindings can be disabled entirely or individually by setting the binding configuration to `false`.

```js
window.$docsify = {
// Disable all key bindings
keyBindings: false,
};
```

```js
window.$docsify = {
keyBindings: {
// Disable individual key bindings
focusSearch: false,
toggleSidebar: false,
},
};
```

## loadNavbar

- Type: `Boolean|String`
Expand Down
Loading