-
Notifications
You must be signed in to change notification settings - Fork 404
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Situation
const { Component, mount, useState, xml } = owl;
const dispatchMouseEnter = (el) => {
const mouseEnterEvent = new MouseEvent("mouseenter", { bubbles: false });
el.dispatchEvent(mouseEnterEvent);
};
let handled = 0;
class App extends Component {
static template = xml`
<main class="App">
<button t-on-click="() => state.synthetic = !state.synthetic">
Toggle synthetic
</button>
<ul>
<t t-foreach="[1, 2, 3]" t-as="i" t-key="i">
<t t-if="state.synthetic">
<li t-on-mouseenter.synthetic="inc" t-esc="i" />
</t>
<t t-else="">
<li t-on-mouseenter="inc" t-esc="i" />
</t>
</t>
</ul>
</main>
`;
state = useState({ synthetic: false });
inc() {
handled++;
}
}
await mount(App, document.body, { dev: true });
dispatchMouseEnter(document.querySelector("li"));
if (handled === 1) {
console.log("First event handled");
} else {
console.error("First event not handled");
}
document.querySelector("button").click();
await new Promise((r) => setTimeout(r, 100));
dispatchMouseEnter(document.querySelector("li"));
if (handled === 2) {
console.log("Second event handled");
} else {
console.error("Second event not handled");
}Issue
As is shown in the console, the first dispatch (with synthetic = false) is handled and the second (with synthetic = true) is not. This is because mouseenter events (along with some others, like focus, blur, load, etc.) do not bubble up to the synthetic listener.
Proposition
I think it could be relevant to prevent or discourage the use of .synthetic on a defined list of events that do not bubble, by logging an error or a warning for instance.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request