Closed
Description
Feature request
Improve accessibility by implementing keyboard bindings/shortcuts for common navigation actions.
Linked PR: #2279
Proposal
Provide the following navigation keyboard bindings/shortcuts for all docsify sites by default:
- Toggle the sidebar menu
- Move focus on the main content area
- Move focus to the search field (and toggle sidebar if necessary)
Because all three of the above shortcuts are associated with DOM elements, keyboard binding hints can be provided to the user by hovering (via title
attribute) or focusing (via aria-keyshortcuts
attribute) on each associated element (sidebar toggle button, the "Skip to main content" element from #2253, and the search input field).
Optional
Allow custom keyboard binding functions to be defined as part of the docsify configuration. Docsify will handle capturing these keyboard shortcuts and invoking the associated function.
Example Implementation
window.$docsify = {
keyBindings: {
// Example: Docsify default shortcut
'toggleSidebar': {
binding: 'alt+t',
label: 'Toggle sidebar menu',
callback(e) {
const toggleElm = document.querySelector('.sidebar-toggle');
if (toggleElm) {
toggleElm.click();
toggleElm.focus();
}
},
},
// Example: Plugin custom shortcut
'myPlugin': {
binding: 'alt+ctrl+shift+meta+a',
label: 'Do a plugin thing',
callback(e) {
// ...
},
},
}
}
Disable key bindings:
window.$docsify = {
keyBindings: false,
}