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

fix: prevent scrolling when focus trap cycles back into the modal #82

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jquense
Copy link
Member

@jquense jquense commented Apr 24, 2023

also fixes a small issue with the alertdialog role fixing #81 and addresses the bug noted in react-bootstrap/react-bootstrap#6579

I was hoping the scroll thing would be as simple as preventDefault on the incoming focus event but that doesn't seem to cut it in Chrome at least, so back to good ol manual scroll position setting.

also fixes a small issue with the `alertdialog` role
@jquense jquense requested a review from kyletsang April 24, 2023 14:42
@@ -51,6 +55,11 @@ class ModalManager {
return getBodyScrollbarWidth(this.ownerDocument);
}

protected getScollingElement() {
const element = getScrollParent(this.getElement());
return isDocument(element) ? element.defaultView! : element;
Copy link
Member Author

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
Copy link
Collaborator

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

Copy link
Member Author

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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "Scroll"

@kyletsang kyletsang linked an issue Apr 25, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modal: accept role as a prop
2 participants