Skip to content

Commit

Permalink
fix(a11y): header navigation list
Browse files Browse the repository at this point in the history
  • Loading branch information
langemike authored and AntonLantukh committed Apr 12, 2024
1 parent 051e46f commit 1d22ab0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
34 changes: 33 additions & 1 deletion packages/ui-react/src/components/Header/Header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@
flex: 1;
align-items: center;

> a {
> ul {
margin: 0;
padding: 0;
list-style-type: none;

li {
float: left;
}
}

a {
height: 36px;
min-height: 36px;
margin: 0 6px;
Expand Down Expand Up @@ -177,6 +187,28 @@
}
}

.navButton {
overflow: visible;

&::after {
position: absolute;
bottom: calc(((variables.$header-height - 36px) / 2) * -1);
left: 0;
width: 100%;
height: 2px;
background-color: variables.$white;
content: '';
}

body:global(.is-tabbing) & {
&:focus {
&::after {
display: none;
}
}
}
}

//
// mediaQueries
// --------------------------------
Expand Down
24 changes: 23 additions & 1 deletion packages/ui-react/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import styles from './Header.module.scss';

type TypeHeader = 'static' | 'fixed';

type NavItem = {
label: string;
to: string;
};

type Props = {
headerType?: TypeHeader;
onMenuButtonClick: () => void;
Expand Down Expand Up @@ -52,6 +57,7 @@ type Props = {
onLanguageClick: (code: string) => void;
favoritesEnabled?: boolean;
siteName?: string;
navItems?: NavItem[];

profilesData?: {
currentProfile: Profile | null;
Expand Down Expand Up @@ -90,6 +96,7 @@ const Header: React.FC<Props> = ({
favoritesEnabled,
siteName,
profilesData: { currentProfile, profiles, profilesEnabled, selectProfile, isSelectingProfile } = {},
navItems = [],
}) => {
const { t } = useTranslation('menu');
const [logoLoaded, setLogoLoaded] = useState(false);
Expand Down Expand Up @@ -197,6 +204,21 @@ const Header: React.FC<Props> = ({
);
};

const renderNav = () => {
if (navItems.length === 0) {
return children;
}
return (
<ul>
{navItems.map((item, index) => (
<li key={index}>
<Button activeClassname={styles.navButton} label={item.label} to={item.to} variant="text" />
</li>
))}
</ul>
);
};

return (
<header className={headerClassName}>
<div className={styles.container}>
Expand All @@ -220,7 +242,7 @@ const Header: React.FC<Props> = ({
<Logo alt={t('logo_alt', { siteName })} src={logoSrc} onLoad={() => setLogoLoaded(true)} />
</div>
)}
<nav className={styles.nav}>{logoLoaded || !logoSrc ? children : null}</nav>
<nav className={styles.nav}>{logoLoaded || !logoSrc ? renderNav() : null}</nav>
<div className={styles.actions}>
{renderSearch()}
{renderLanguageDropdown()}
Expand Down
22 changes: 0 additions & 22 deletions packages/ui-react/src/containers/Layout/Layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,3 @@
.main {
height: 100%;
}

.headerButton {
overflow: visible;

&::after {
position: absolute;
bottom: calc(((variables.$header-height - 36px) / 2) * -1);
left: 0;
width: 100%;
height: 2px;
background-color: variables.$white;
content: '';
}

body:global(.is-tabbing) & {
&:focus {
&::after {
display: none;
}
}
}
}
10 changes: 4 additions & 6 deletions packages/ui-react/src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ const Layout = () => {
);
};

const navItems = [{ label: t('home'), to: '/' }, ...menu.map((item) => ({ label: item.label, to: playlistURL(item.contentId) }))];

const containerProps = { inert: sideBarOpen ? '' : undefined }; // inert is not yet officially supported in react

return (
Expand Down Expand Up @@ -197,12 +199,8 @@ const Layout = () => {
selectProfile: ({ avatarUrl, id }) => selectProfile.mutate({ id, avatarUrl }),
isSelectingProfile: selectProfile.isLoading,
}}
>
<Button activeClassname={styles.headerButton} label={t('home')} to="/" variant="text" />
{menu.map((item) => (
<Button activeClassname={styles.headerButton} key={item.contentId} label={item.label} to={playlistURL(item.contentId)} variant="text" />
))}
</Header>
navItems={navItems}
/>
<main id="content" className={styles.main} tabIndex={-1}>
<Outlet />
</main>
Expand Down

0 comments on commit 1d22ab0

Please sign in to comment.