mirror of
https://github.com/hazemKrimi/react-weather-app.git
synced 2026-05-01 18:30:25 +00:00
Fix search bar event listener
This commit is contained in:
@@ -8,7 +8,7 @@ const SearchBar: React.FC = () => {
|
||||
const history = useHistory();
|
||||
|
||||
const search = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === 'Enter' && query !== '') {
|
||||
if ((event.key === 'Enter' || event.keyCode === 13) && query !== '') {
|
||||
history.push(`/search/${query}`);
|
||||
setQuery('');
|
||||
}
|
||||
@@ -19,7 +19,7 @@ const SearchBar: React.FC = () => {
|
||||
<Input
|
||||
placeholder='Search'
|
||||
value={query}
|
||||
onKeyPress={search}
|
||||
onKeyUp={search}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setQuery(event.target.value)}
|
||||
/>
|
||||
<img src={SearchIcon} alt='Search icon' />
|
||||
|
||||
@@ -16,6 +16,7 @@ export const Input = styled.input`
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
user-select: text !important;
|
||||
|
||||
&::placeholder {
|
||||
color: rgba(0, 0, 0, 0.5);
|
||||
|
||||
Reference in New Issue
Block a user