Skip to content

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