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:
Kevin Kipp 2018-10-12 00:50:12 -05:00 committed by Yangshun Tay
parent fe500dea82
commit e880756614

View file

@ -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