| 12 | } |
| 13 | |
| 14 | class SearchBox extends Component<Props> { |
| 15 | static defaultProps = { |
| 16 | className: '', |
| 17 | } |
| 18 | |
| 19 | onKeyPress = (event: KeyboardEvent<HTMLInputElement>) => { |
| 20 | if (event.key === 'Enter') { |
| 21 | const { value } = event.currentTarget |
| 22 | this.onSearch(value) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | onSearch = (query: string) => { |
| 27 | if (query === '') { |
| 28 | this.props.router.push({ pathname: topicPath(everythingTopicId) }) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | this.props.router.push({ pathname: topicPath(everythingTopicId), query: { q: query } }) |
| 33 | } |
| 34 | |
| 35 | render = () => ( |
| 36 | <p className={classNames(this.props.className, 'form-group text-center')}> |
| 37 | <input |
| 38 | aria-label="Search" |
| 39 | className="searchBoxInput form-control p-3" |
| 40 | onKeyPress={this.onKeyPress} |
| 41 | placeholder="Start with a search" |
| 42 | type="search" |
| 43 | /> |
| 44 | </p> |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | export default SearchBox |
nothing calls this directly
no test coverage detected