import { Button } from '@openfun/cunningham-react'; import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { css } from 'styled-components'; import { Box } from '@/components'; import { useCunninghamTheme } from '@/cunningham'; import { MAIN_LAYOUT_ID } from '@/layouts/conf'; export const SkipToContent = () => { const { t } = useTranslation(); const router = useRouter(); const { spacingsTokens } = useCunninghamTheme(); const [isVisible, setIsVisible] = useState(false); // Reset focus after route change so first TAB goes to skip link useEffect(() => { const handleRouteChange = () => { (document.activeElement as HTMLElement)?.blur(); document.body.setAttribute('tabindex', '-1'); document.body.focus({ preventScroll: true }); setTimeout(() => { document.body.removeAttribute('tabindex'); }, 100); }; router.events.on('routeChangeComplete', handleRouteChange); return () => { router.events.off('routeChangeComplete', handleRouteChange); }; }, [router.events]); const handleClick = (e: React.MouseEvent) => { e.preventDefault(); const mainContent = document.getElementById(MAIN_LAYOUT_ID); if (mainContent) { mainContent.focus(); mainContent.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }; return ( ); };