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

♿️ Add focus trap to the menu #955

Merged
merged 7 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[ignore]
<PROJECT_ROOT>/.next
.*/node_modules/resolve/test/resolver/malformed_package_json
.*/node_modules/jsonlint-mod

[include]
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"next": "^12.0.0",
"next-sitemap": "^1.3.16",
"prettier": "2.5.1",
"prop-types": "^15.8.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-test-renderer": "^17.0.1"
Expand Down Expand Up @@ -81,6 +82,7 @@
"testEnvironment": "jsdom"
},
"dependencies": {
"focus-trap-react": "^8.9.0",
"next-pwa": "^5.4.4"
}
}
65 changes: 34 additions & 31 deletions src/components/Layout/Hamburger/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import React, { type Element } from 'react'
import Router from 'next/router'
import FocusTrap from 'focus-trap-react'

import MenuLink from './MenuLink'
import OpenIcon from './OpenIcon'
Expand Down Expand Up @@ -31,38 +32,40 @@ const Hamburger = (): Element<'div'> => {
</button>

{isOpen && (
<nav className={styles.menu}>
<div className={styles.closeContainer}>
<button
aria-label="Close navigation menu"
className={styles.button}
onClick={() => setIsOpen(false)}
>
<CloseIcon />
</button>
</div>
<FocusTrap active={isOpen}>
<nav className={styles.menu}>
<div className={styles.closeContainer}>
<button
aria-label="Close navigation menu"
className={styles.button}
onClick={() => setIsOpen(false)}
>
<CloseIcon />
</button>
</div>

<ul className={styles.links}>
<li>
<MenuLink href="/" text="Home" />
</li>
<li>
<MenuLink href="/about" text="About" />
</li>
<li>
<MenuLink href="/contributors" text="Contributors" />
</li>
<li>
<MenuLink href="/related-tools" text="Related tools" />
</li>
<li>
<MenuLink
href="https://github.com/carloscuesta/gitmoji"
text="GitHub"
/>
</li>
</ul>
</nav>
<ul className={styles.links}>
<li>
<MenuLink href="/" text="Home" />
</li>
<li>
<MenuLink href="/about" text="About" />
</li>
<li>
<MenuLink href="/contributors" text="Contributors" />
</li>
<li>
<MenuLink href="/related-tools" text="Related tools" />
</li>
<li>
<MenuLink
href="https://github.com/carloscuesta/gitmoji"
text="GitHub"
/>
</li>
</ul>
</nav>
</FocusTrap>
)}
</div>
)
Expand Down