GlobalSearch for navbar integration with autocomplete, and AnimeSearch for full-page search results.
GlobalSearch
A dropdown search component with autocomplete suggestions, keyboard navigation, and recent search history.Import
Props
Optional CSS classes to apply to the search container
Features
- Autocomplete Suggestions: Real-time anime suggestions from Jikan API
- Recent Search History: Stores last 5 searches in localStorage
- Keyboard Navigation: Arrow keys to navigate, Enter to select, Escape to close
- Keyboard Shortcut: Press
/anywhere to focus search - Debounced Search: 300ms debounce to reduce API calls
- Error Handling: Rate limit detection and error states
Usage
Data Structures
The component works with search suggestions from the Jikan API:Keyboard Shortcuts
- Global
- Within Dropdown
/- Focus search input from anywhereEscape- Close suggestions and blur input
localStorage Keys
The component uses localStorage for persistence:Array of recent search queries (max 5 items)
API Integration
Searches are performed against the Jikan v4 API:Source Reference
Source code:~/workspace/source/src/components/GlobalSearch.tsx
AnimeSearch
A full-page search component with grid results and pagination using theuseAnimeSearch hook.
Import
Props
No props required - fully self-contained component.Features
- Grid Layout: Responsive grid (2-5 columns based on screen size)
- Pagination: Previous/Next controls with page tracking
- Loading States: Spinner indicator during searches
- Error Handling: Error messages for failed requests
- Image Fallbacks: SVG icons when cover art is unavailable
- Genre Tags: Display up to 2 genres per anime
Usage
Hook Integration
Uses theuseAnimeSearch hook for data fetching:
src/hooks/useAnime.ts and provides automatic state management for search queries.
Data Format
Works with the standardizedAnime interface:
Styling Features
Dynamic gradient backgrounds for cards without cover art:Responsive Grid
- Mobile: 2 columns
- Small: 3 columns
- Medium: 4 columns
- Large: 5 columns
Source Reference
Source code:~/workspace/source/src/components/AnimeSearch.tsx
Common Search Patterns
Implementing Search in Custom Pages
Combining Both Components
Related
Search API
Learn about the searchAnime() API function
Navigation Components
Integrate search into navigation