Skip to content

Commit

Permalink
Typing should focus on searchbar #2
Browse files Browse the repository at this point in the history
  • Loading branch information
nickolasbenakis authored and nickolasbenakis committed Dec 9, 2019
1 parent f71c0ed commit f8d95bf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/searchbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class Searchbar extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.searchBarRef = React.createRef();
this.handleFocus = this.handleFocus.bind(this);
document.addEventListener('keypress', this.handleFocus);
}

handleFocus() {
this.searchBarRef.current.focus();
}

handleChange(event) {
Expand All @@ -16,11 +23,19 @@ class Searchbar extends React.Component {
}

render() {
/* eslint-disable jsx-a11y/no-autofocus */
/* eslint-disable no-trailing-spaces */
const { search, searchbarFixed } = this.props;
return (
<div className={`search ${searchbarFixed ? 'search-fixed' : ''}`}>
<div className="searchbar-container">
<input defaultValue={search || ''} onChange={this.handleChange} placeholder="Search" />
<input
ref={this.searchBarRef}
defaultValue={search || ''}
onChange={this.handleChange}
placeholder="Search"
autoFocus
/>
</div>
<div className="checkboxes">
<div>
Expand Down

0 comments on commit f8d95bf

Please sign in to comment.