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 modal event listeners #37128

Merged
merged 9 commits into from Sep 15, 2022
Merged

Fix modal event listeners #37128

merged 9 commits into from Sep 15, 2022

Conversation

ghost
Copy link

@ghost ghost commented Sep 12, 2022

Add a check to ensure that the element that triggered the event is still present in the DOM.

closes #37126

Supersedes #37143

Add a check to ensure that the element that triggered the event is still present in the DOM.
@GeoSot
Copy link
Member

GeoSot commented Sep 14, 2022

@jbroutier Thank you for your PR.
Can you please a test-case to justify the change?

@ghost
Copy link
Author

ghost commented Sep 15, 2022

@GeoSot I've added a test case as requested.

I've also updated the fix to check both events instead of just the mousedown one for testability purposes. Otherwise in one case I cannot trigger the event handler of the modal and in the other case I cannot reproduce the bug.

@GeoSot
Copy link
Member

GeoSot commented Sep 15, 2022

I've linted a bit, but got another idea too.
You may, instead of two contain checks, to try this

        if (this._element !== event.target || this._element !== event2.target) {
          return
        }

it should work too and it covers both cases

@GeoSot GeoSot merged commit 6f65df4 into twbs:main Sep 15, 2022
@XhmikosR XhmikosR changed the title Fix modal event listeners (#37126) Fix modal event listeners Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Since 5.2.1 modals closes on content removal
2 participants