Skip to content
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

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
27 changes: 25 additions & 2 deletions apps/site/components/withNavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
'use client';

import classNames from 'classnames';
import { useLocale } from 'next-intl';
import { useTheme } from 'next-themes';
import type { FC } from 'react';
import type { FC, KeyboardEvent } 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 classNameOnTabPress = classNames(
araujogui marked this conversation as resolved.
Show resolved Hide resolved
'!fixed left-0 m-3 -translate-y-16 p-3 transition-all focus:translate-y-0',
{ '-translate-y-16': !tabPressed, 'translate-y-0': tabPressed }
);

const locale = useLocale();

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

const handleTabPress = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Tab') {
setTabPressed(prev => !prev);
}
};
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<div onKeyDown={handleTabPress}>
<Button
className={classNameOnTabPress}
aria-hidden={!tabPressed}
href="#main"
>
Skip to main content
yaten2302 marked this conversation as resolved.
Show resolved Hide resolved
</Button>

<WithBanner section="index" />

<NavBar
Expand Down
Loading