-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(a11y): remove outline when user is not tabbing
- Loading branch information
1 parent
ddcfc91
commit 5fe1665
Showing
3 changed files
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const attachAccessibilityListener = () => { | ||
let isTabbing = false; | ||
|
||
// when the user presses the Tab key, we add a `is-tabbing` className to the body element, so we can enable outline | ||
// focus for keyboard users | ||
document.addEventListener('keydown', (event) => { | ||
if (event.key === 'Tab' && !isTabbing) { | ||
isTabbing = true; | ||
document.body.classList.add('is-tabbing'); | ||
} | ||
}); | ||
|
||
// remove the `is-tabbing` className when the user uses a mouse again to interact with elements | ||
document.addEventListener('mousedown', () => { | ||
if (isTabbing) { | ||
isTabbing = false; | ||
document.body.classList.remove('is-tabbing'); | ||
} | ||
}); | ||
}; |