Skip to content

Commit

Permalink
Merge pull request dubinc#210 from steven-tey/focus-trap-no-scroll
Browse files Browse the repository at this point in the history
Add no scroll to focus trap
  • Loading branch information
steven-tey authored May 21, 2023
2 parents 05d8ecd + d07c952 commit 2175cb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/ui/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export default function Modal({
return (
<AnimatePresence>
{(setShowModal ? showModal : true) && (
<FocusTrap focusTrapOptions={{ initialFocus: false }}>
<FocusTrap
focusTrapOptions={{
initialFocus: false,
onActivate: () => {
// prevent scroll outside of modal
document.body.style.overflow = "hidden";
},
}}
>
<div className="absolute">
<motion.div
ref={mobileModalRef}
Expand Down
10 changes: 9 additions & 1 deletion components/shared/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ export default function Modal({
return (
<AnimatePresence>
{showModal && (
<FocusTrap focusTrapOptions={{ initialFocus: false }}>
<FocusTrap
focusTrapOptions={{
initialFocus: false,
onActivate: () => {
// prevent scroll outside of modal
document.body.style.overflow = "hidden";
},
}}
>
<div className="absolute">
<motion.div
ref={mobileModalRef}
Expand Down

0 comments on commit 2175cb0

Please sign in to comment.