parent
21040bca36
commit
e6d5f8f754
2 changed files with 42 additions and 22 deletions
@ -1,24 +1,21 @@ |
||||
import React from 'react'; |
||||
import React, { useState } from 'react'; |
||||
import TextField from '@material-ui/core/TextField'; |
||||
|
||||
export class SearchBar extends React.Component { |
||||
state = { |
||||
text_value: false, |
||||
} |
||||
export function SearchBar(props) { |
||||
const [ textValue, setTextValue ] = useState(false); |
||||
const { onSubmit } = props; |
||||
|
||||
onSubmitHandler = () => { this.props.onSubmit(this.state.text_value); } |
||||
onChangeHandler = (e) => { this.setState({ text_value: e.target.value }); } |
||||
keyDownHandler = (e) => { |
||||
function onSubmitHandler() { onSubmit(textValue); } |
||||
function onChangeHandler(e) { setTextValue(e.target.value); } |
||||
function keyDownHandler(e) { |
||||
if (e.key === 'Enter') { |
||||
this.onSubmitHandler(); |
||||
onSubmitHandler(); |
||||
} |
||||
} |
||||
|
||||
render() { |
||||
return ( |
||||
<> |
||||
<TextField variant="outlined" fullWidth label="Search" type="text" onChange={this.onChangeHandler} onKeyDown={this.keyDownHandler} /> |
||||
</> |
||||
); |
||||
} |
||||
return ( |
||||
<> |
||||
<TextField variant="outlined" fullWidth label="Search" type="text" onChange={onChangeHandler} onKeyDown={keyDownHandler} /> |
||||
</> |
||||
); |
||||
} |
Loading…
Reference in new issue