dioxus
dioxus copied to clipboard
Need for synchronous PreventDefault across Tao/Wry boundary
Unfortunately, there's no way today to conditionally call PreventDefault across the Tao/Wry boundary.
Developers should be able to disable default in a way that's not just hardcoded fields - IE allowing default behavior when right-clicking links in the browser.
The FFI boundary is particularly challenging because we cannot synchronously handle the event.
I think the solution is to always trap the event and prevent default.
Then, ff 1) the event has default behavior and 2) the user didn't prevent that default behavior in their Dioxus handler, then we should craft the event again and push it back in the real dom.
we should craft the event again and push it back in the real dom.
from my (maybe flawed) testing in the chrome console, synthetic events still manage to have a different behaviour:
(function(a) {
//document.body.appendChild(a);
//a.setAttribute('href', 'https://github.com');
a.setAttribute('target', '_blank');
a.dispatchEvent((function(e) {
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
true, false, false, false, 0, null);
return e
}(document.createEvent('MouseEvents'))))
}(document.querySelector('a[href^=http]')))
This opens a new tab and focuses it, as opposed to opening it in the background when the cmd-click is done using the real mouse
We cannot create an event that is identical to the event triggered by the browser. Events that are triggered by a user are trusted. Events that are modified by javascript will not be trusted