-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
52 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useState, useEffect } from "react"; | ||
import useWindow from "../../hooks/useWindow"; | ||
|
||
function FocusVisiblePolyfill() { | ||
const [isKeyboardMode, setIsKeyboardMode] = useState(false); | ||
const onKeyDown = () => setIsKeyboardMode(true); | ||
const onMouseDown = () => setIsKeyboardMode(false); | ||
const window = useWindow(); | ||
|
||
useEffect(() => { | ||
if (window) { | ||
window.addEventListener("keydown", onKeyDown); | ||
window.addEventListener("mousedown", onMouseDown); | ||
} | ||
|
||
return () => { | ||
if (window) { | ||
window.removeEventListener("keydown", onKeyDown); | ||
window.removeEventListener("mousedown", onMouseDown); | ||
} | ||
}; | ||
}, [window]); | ||
|
||
useEffect(() => { | ||
if (window) { | ||
window.document.body.dataset.basisKeyboardMode = String(isKeyboardMode); | ||
} | ||
}, [window, isKeyboardMode]); | ||
|
||
return null; | ||
} | ||
|
||
export default FocusVisiblePolyfill; |
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
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
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
6c8da38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: