Spaces:
Runtime error
Runtime error
File size: 911 Bytes
ca10871 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import React, { useState } from 'react';
import { TextField, Button, Box } from '@mui/material';
const SearchBar = ({ onSearch }) => {
const [query, setQuery] = useState('');
const handleSearchClick = () => {
onSearch(query);
};
const handleKeyDown = (e) => {
if (e.key === 'Enter') {
handleSearchClick();
}
};
return (
<Box sx={{ display: 'flex', justifyContent: 'center', my: 4 }}>
<TextField
variant="outlined"
label="Search"
fullWidth
sx={{ maxWidth: '800px' }}
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={handleKeyDown} // Add this line to handle Enter key press
/>
<Button
variant="contained"
color="primary"
onClick={handleSearchClick}
sx={{ ml: 2 }}
>
Search
</Button>
</Box>
);
};
export default SearchBar;
|