We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_:hammer_and_wrench: Refactor suggestion_
Add keyboard navigation for search results.
The search results can only be navigated using a mouse. Consider adding keyboard navigation for better accessibility.
+ const [selectedIndex, setSelectedIndex] = useState(-1); + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (!search || filteredCourts.length === 0) return; + + switch(e.key) { + case 'ArrowDown': + e.preventDefault(); + setSelectedIndex(prev => Math.min(prev + 1, filteredCourts.length - 1)); + break; + case 'ArrowUp': + e.preventDefault(); + setSelectedIndex(prev => Math.max(prev - 1, -1)); + break; + case 'Enter': + if (selectedIndex >= 0) { + navigate(`/courts/${filteredCourts[selectedIndex].id}`); + setSearch(""); + } + break; + } + }; return ( <SearchBarContainer> <StyledSearchbar dir="auto" type="text" placeholder="Search" value={search} onChange={(e) => setSearch(e.target.value)} + onKeyDown={handleKeyDown} /> {search && filteredCourts.length > 0 && ( <SearchResultsContainer> {filteredCourts.map((court, index) => ( <StyledCard key={court.id} - selected={court.id === currentCourtId} + selected={court.id === currentCourtId || index === selectedIndex} onClick={() => { navigate(`/courts/${court.id}`); setSearch(""); }} >
Committable suggestion skipped: line range outside the PR's diff.
Originally posted by @coderabbitai[bot] in #1821 (comment)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Add keyboard navigation for search results.
The search results can only be navigated using a mouse. Consider adding keyboard navigation for better accessibility.
Originally posted by @coderabbitai[bot] in #1821 (comment)
The text was updated successfully, but these errors were encountered: