Skip to content

Commit

Permalink
Add skip to content button
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm committed Dec 30, 2023
1 parent 9f6defc commit c4d9193
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/components/Layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,26 @@
}
}
}

.skip-to-main {
position: absolute;
z-index: 999999;
height: 4.8rem;
border-radius: 0.6rem;
background-color: var(--color-surface1);
margin: 0.4rem;
padding-inline: 2rem;
opacity: 0;
pointer-events: none;
cursor: pointer;

&:focus {
opacity: 1;
pointer-events: all;
outline: 2px solid black;
}

@include lg {
margin: 0.8rem;
}
}
24 changes: 19 additions & 5 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ import Header from './Header'
import styles from './Layout.module.scss'

const Layout: ParentComponent = (props) => {
let ref: HTMLElement | undefined

const skipNav = () => {
console.log('skip nav', ref)
ref?.focus()
}

return (
<div class={styles.layout}>
<Header />
<main class={styles.main}>{props.children}</main>
<Footer />
</div>
<>
<button onClick={skipNav} class={styles.skipToMain} aria-label="Navigáció átugrása">
<span>Navigáció átugrása</span>
</button>
<div class={styles.layout}>
<Header />
<main ref={ref} tabindex="-1" class={styles.main}>
{props.children}
</main>
<Footer />
</div>
</>
)
}

Expand Down
2 changes: 2 additions & 0 deletions src/scss/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ body {
--text-family-content: -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
--text-family-content-heading: var(--text-family-content);

--color-surface1: var(--color-gray100);

--page-width: 1200px;
--page-padding: 1rem;

Expand Down

0 comments on commit c4d9193

Please sign in to comment.