MDL-83223 core: Use capture with addEventListener to intercept events

The issue is that Bootstrap’s dropdown component likely stops
event propagation after the first click to manage its own
dropdown behavior. This prevents your click event handler from
running on subsequent clicks.

To fix this, we can handle the event before Bootstrap’s code stops
the propagation by using capture option with addEventListener.
This commit is contained in:
meirzamoodle
2024-12-04 10:37:02 +07:00
parent 7da8af1006
commit 5e078e4a78
3 changed files with 6 additions and 5 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4 -3
View File
@@ -326,12 +326,13 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'],
}.bind(this));
// Close the popover if any other part of the page is clicked.
$('html').click(function(e) {
var target = $(e.target);
document.addEventListener('click', (e) => {
const target = e.target;
// Check if the click is outside the root element.
if (!this.root.is(target) && !this.root.has(target).length) {
this.closeMenu();
}
}.bind(this));
}, true); // `true` makes it a capture phase event listener.
customEvents.define(this.getContentContainer(), [
customEvents.events.scrollBottom