mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-28 14:08:21 +02:00
feat: add keyboard shortcut to focus search (#1028)
* feat: add keyboard shortcut to focus search * refactor: use const instead of let * refactor: check target and bail if not body
This commit is contained in:
parent
fe500dea82
commit
e880756614
1 changed files with 18 additions and 0 deletions
|
@ -107,6 +107,24 @@ class Site extends React.Component {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{this.props.config.algolia && (
|
||||||
|
<script
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `
|
||||||
|
document.addEventListener('keyup', function(e) {
|
||||||
|
if (e.target !== document.body) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// keyCode for '/' (slash)
|
||||||
|
if (e.keyCode === 191) {
|
||||||
|
const search = document.getElementById('search_input_react');
|
||||||
|
search && search.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{this.props.config.algolia &&
|
{this.props.config.algolia &&
|
||||||
(this.props.config.algolia.algoliaOptions ? (
|
(this.props.config.algolia.algoliaOptions ? (
|
||||||
<script
|
<script
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue