-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
feat: add keyboard shortcut to focus search #1028
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,21 @@ class Site extends React.Component { | |
}} | ||
/> | ||
)} | ||
{this.props.config.algolia && ( | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
document.addEventListener('keyup', function(e) { | ||
// keyCode for '/' (slash) | ||
if (e.keyCode === 191) { | ||
var search = document.getElementById('search_input_react'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Out of curiosity - do these inlined scripts somehow get run through babel? I was surprised to see that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope these scripts do not get processed through Babel, so we have to be careful about not using new language features. |
||
search && search.focus(); | ||
} | ||
}); | ||
`, | ||
}} | ||
/> | ||
)} | ||
{this.props.config.algolia && | ||
(this.props.config.algolia.algoliaOptions ? ( | ||
<script | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
here so that we only focus on the search bar when no other items on the page are in focus.
Try your current script vs the script with the
e.target
checking on https://reasonml.github.io/en/try and you'll see why it's important to add that line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect - I thought that might be an issue. Thanks!