import { useEffect, useState } from 'react' import { t } from '@/lib/i18n' interface SkipLink { id: string label: string targetId: string } const SKIP_LINKS: SkipLink[] = [ { id: 'skip-main', label: 'navigation.skipToMain', targetId: 'main-content' }, { id: 'skip-filters', label: 'navigation.skipToFilters', targetId: 'filters-section' }, { id: 'skip-articles', label: 'navigation.skipToArticles', targetId: 'articles-section' }, ] export function SkipLinks(): React.ReactElement | null { const [isVisible, setIsVisible] = useState(false) useEffect(() => { const handleKeyDown = (e: KeyboardEvent): void => { if (e.key === 'Tab' && !e.shiftKey) { setIsVisible(true) } } const handleKeyUp = (e: KeyboardEvent): void => { if (e.key === 'Tab' && !e.shiftKey) { setIsVisible(true) } } const handleClick = (): void => { setIsVisible(false) } document.addEventListener('keydown', handleKeyDown) document.addEventListener('keyup', handleKeyUp) document.addEventListener('click', handleClick, true) document.addEventListener('mousedown', handleClick, true) return () => { document.removeEventListener('keydown', handleKeyDown) document.removeEventListener('keyup', handleKeyUp) document.removeEventListener('click', handleClick, true) document.removeEventListener('mousedown', handleClick, true) } }, []) if (!isVisible) { return null } return (
) } function SkipLinkItem({ link, onFocus }: { link: SkipLink; onFocus: () => void }): React.ReactElement { const handleClick = (e: React.MouseEvent): void => { e.preventDefault() const target = document.getElementById(link.targetId) if (target) { target.focus() target.scrollIntoView({ behavior: 'smooth', block: 'start' }) } } return ( {t(link.label)} ) }