import { useEffect } from 'react'; export function useKeyboardNav(handlers: Record void>) { useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { const handler = handlers[e.key]; if (handler && !['INPUT', 'TEXTAREA'].includes((e.target as HTMLElement).tagName)) { e.preventDefault(); handler(); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [handlers]); }