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:35:36 +07:00
parent a798b1db39
commit 48e652623d
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