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'; |
import TextField from '@material-ui/core/TextField'; |
||||||
|
|
||||||
export class SearchBar extends React.Component { |
export function SearchBar(props) { |
||||||
state = { |
const [ textValue, setTextValue ] = useState(false); |
||||||
text_value: false, |
const { onSubmit } = props; |
||||||
} |
|
||||||
|
|
||||||
onSubmitHandler = () => { this.props.onSubmit(this.state.text_value); } |
function onSubmitHandler() { onSubmit(textValue); } |
||||||
onChangeHandler = (e) => { this.setState({ text_value: e.target.value }); } |
function onChangeHandler(e) { setTextValue(e.target.value); } |
||||||
keyDownHandler = (e) => { |
function keyDownHandler(e) { |
||||||
if (e.key === 'Enter') { |
if (e.key === 'Enter') { |
||||||
this.onSubmitHandler(); |
onSubmitHandler(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
render() { |
return ( |
||||||
return ( |
<> |
||||||
<> |
<TextField variant="outlined" fullWidth label="Search" type="text" onChange={onChangeHandler} onKeyDown={keyDownHandler} /> |
||||||
<TextField variant="outlined" fullWidth label="Search" type="text" onChange={this.onChangeHandler} onKeyDown={this.keyDownHandler} /> |
</> |
||||||
</> |
); |
||||||
); |
|
||||||
} |
|
||||||
} |
} |
Loading…
Reference in new issue