-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix: prevent scrolling when focus trap cycles back into the modal #82
base: main
Are you sure you want to change the base?
Conversation
also fixes a small issue with the `alertdialog` role
@@ -51,6 +55,11 @@ class ModalManager { | |||
return getBodyScrollbarWidth(this.ownerDocument); | |||
} | |||
|
|||
protected getScollingElement() { | |||
const element = getScrollParent(this.getElement()); | |||
return isDocument(element) ? element.defaultView! : element; |
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.
maybe this is over complicating things? people shouldn't actually be rendering modals into not-the-body
@@ -299,9 +300,7 @@ const Modal: React.ForwardRefExoticComponent< | |||
removeFocusListenerRef.current = listen( | |||
document as any, | |||
'focus', | |||
// the timeout is necessary b/c this will run before the new modal is mounted |
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.
Looks like this was necessary to resolve the TypeError: Converting circular structure to JSON
error in the tests
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.
Yeah I'm confused why tho. It doesn't seem necessary in real life. Gotta dig in a bit
@@ -51,6 +55,11 @@ class ModalManager { | |||
return getBodyScrollbarWidth(this.ownerDocument); | |||
} | |||
|
|||
protected getScollingElement() { |
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.
Typo in "Scroll"
also fixes a small issue with the
alertdialog
role fixing #81 and addresses the bug noted in react-bootstrap/react-bootstrap#6579I was hoping the scroll thing would be as simple as
preventDefault
on the incomingfocus
event but that doesn't seem to cut it in Chrome at least, so back to good ol manual scroll position setting.