// SearchBar.jsx import React, { useEffect, useRef } from 'react'; import { FormControl, OutlinedInput, InputAdornment, IconButton, useTheme } from '@mui/material'; import SearchOutlined from '@mui/icons-material/SearchOutlined'; import ClearIcon from '@mui/icons-material/Clear'; const SearchBar = ({ value, onChange, sx, placeholder = 'Search (Ctrl + K)' }) => { const theme = useTheme(); const inputRef = useRef(null); /* ============================================= || handleKeyPress (CTRL + K) and ESC ||============================================= */ useEffect(() => { const handleKeyPress = (event) => { // Focus input with CTRL + K / CMD + K if (event.key === 'k' && (event.metaKey || event.ctrlKey)) { event.preventDefault(); inputRef.current?.focus(); } // ESC removes focus if (event.key === 'Escape' && document.activeElement === inputRef.current) { inputRef.current.blur(); } }; document.addEventListener('keydown', handleKeyPress); return () => document.removeEventListener('keydown', handleKeyPress); }, []); return ( } endAdornment={ onChange({ target: { value: '' } })}> } /> ); }; export default SearchBar;