Carousel links + press "Enter" to search (pu juste le boutton)

This commit is contained in:
Victor Turgeon
2022-10-30 13:13:34 -07:00
parent 52a890fd6e
commit 2f14c6a842
3 changed files with 27 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';
const ResearchBar = () => {
@@ -8,8 +8,9 @@ const ResearchBar = () => {
const navigate = useNavigate();
const [value, setValue] = useState("");
const search = async (query) => {
navigate('/morceaux', { state: { query: query} });
navigate('/morceaux', { state: { query: query } });
}
const handleValueChange = async (value) => {
@@ -18,7 +19,15 @@ const ResearchBar = () => {
return (
<div className="research-container">
<input className="research-input" value={value} onChange={(e) => handleValueChange(e.target.value)} placeholder="Rechercher..."></input>
<input className="research-input"
onKeyDown={(e) => {
if (e.key === "Enter") {
search(value);
}
}}
value={value}
onChange={(e) => handleValueChange(e.target.value)}
placeholder="Rechercher..."></input>
<button className="research-btn" onClick={() => search(value)}>
<div className="fa fa-search" />
</button>