I have a search field in my application and I have implemented a custom suggestion dropdown with it. When user types any keyword in the search field I query a search index and once results are fetched I show them in a custom dropdown under the search field. The code looks something like this:
import "./styles.css";
import {useState} from 'react';
export default function Search() {
const [results, setResults] = useState([]);
return (
<div>
<input
placeholder="search"
onChange={() => {// I fetch results and set them in state}}
type="text" />
{
results && <div className="my-suggestion-dropdown">
<h4>Suggestions</h4>
<a>First suggestion</a>
<a>Second suggestion</a>
// so and so so forth
</div>
</div>
}
</div>
);
}
This works fine. I want the suggestion dropdown to be accessible so the user can navigate using tabs. Once the dropdown is open if the user presses tab then focus should go into the dropdown and once the dropdown has been traversed focus should move to element after the input field.
How can I implement this behavior?