Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions frontend/src/components/Layout/MainLayout.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ export const useMainLayoutStyles = makeStyles({
width: '100vw',
overflow: 'hidden',
},
skipLink: {
position: 'absolute',
top: '-40px',
left: '0',
zIndex: 1000,
padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`,
backgroundColor: tokens.colorBrandBackground,
color: tokens.colorNeutralForegroundOnBrand,
fontWeight: tokens.fontWeightSemibold,
textDecorationLine: 'none',
borderBottomRightRadius: tokens.borderRadiusMedium,
transitionProperty: 'top',
transitionDuration: tokens.durationFast,
Comment thread
romanlutz marked this conversation as resolved.
Outdated
':focus-visible': {
top: '0',
},
},
topBar: {
height: '60px',
backgroundColor: tokens.colorNeutralBackground3,
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/components/Layout/MainLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,32 @@ describe("MainLayout", () => {
expect(mockedVersionApi.getVersion).toHaveBeenCalled();
});
});

it("renders a skip link as the first focusable element that targets the main landmark", async () => {
mockedVersionApi.getVersion.mockResolvedValue({ version: "1.0.0" });

const { container } = renderWithProvider(
<MainLayout {...defaultProps}>
<div>Content</div>
</MainLayout>
);

const skipLink = screen.getByRole("link", { name: /skip to main content/i });
expect(skipLink).toHaveAttribute("href", "#main-content");

const main = container.querySelector("main");
expect(main).toHaveAttribute("id", "main-content");
expect(main).toHaveAttribute("tabIndex", "-1");

// The skip link must be the first focusable element in the shell so
// keyboard users reach it on the very first Tab press.
const focusable = container.querySelectorAll<HTMLElement>(
'a[href], button, [tabindex]:not([tabindex="-1"])'
);
expect(focusable[0]).toBe(skipLink);
Comment thread
romanlutz marked this conversation as resolved.

await waitFor(() => {
expect(mockedVersionApi.getVersion).toHaveBeenCalled();
});
});
});
7 changes: 6 additions & 1 deletion frontend/src/components/Layout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export default function MainLayout({

return (
<div className={styles.root}>
<a href="#main-content" className={styles.skipLink}>
Skip to main content
</a>
<div className={styles.topBar}>
<Tooltip
content={
Expand Down Expand Up @@ -86,7 +89,9 @@ export default function MainLayout({
canManageConfiguration={canManageConfiguration}
/>
</aside>
<main className={styles.main}>{children}</main>
<main id="main-content" tabIndex={-1} className={styles.main}>
{children}
</main>
</div>
</div>
)
Expand Down