Skip to content

init: add skip-to-main-content shortcut #7390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
20 changes: 19 additions & 1 deletion apps/site/components/withNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,44 @@
import { useLocale } from 'next-intl';
import { useTheme } from 'next-themes';
import type { FC } from 'react';
import { useState } from 'react';

import NavBar from '@/components/Containers/NavBar';
import WithBanner from '@/components/withBanner';
import { useSiteNavigation } from '@/hooks';
import { useRouter, usePathname } from '@/navigation.mjs';
import { availableLocales } from '@/next.locales.mjs';

import Button from './Common/Button';

const WithNavBar: FC = () => {
const { navigationItems } = useSiteNavigation();
const { resolvedTheme, setTheme } = useTheme();
const { replace } = useRouter();
const pathname = usePathname();
const [tabPressed, setTabPressed] = useState(false);

const locale = useLocale();

const toggleCurrentTheme = () =>
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');

const handleTabPress = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Tab') {
setTabPressed(prev => !prev);
}
};

return (
<div>
<div onKeyDown={handleTabPress}>
<Button
className="${tabPressed ? 'translate-y-0' : '-translate-y-16' !fixed left-0 m-3 -translate-y-16 p-3 transition-all focus:translate-y-0"
aria-hidden={!tabPressed}
href="#main"
>
Skip to main content
</Button>

<WithBanner section="index" />

<NavBar
Expand Down
Loading