Merge branch 'master' into fix-event-bubbling

This commit is contained in:
Evan Almloff committed 2023-09-17 20:00:22 -05:00
1 parent c8fca7b321
commit 98335bd9a6
368 files changed
+1877 -13498

No files matched your search

+29 -11
View File
@@ -390,7 +390,11 @@ class Interpreter {
function handler(event, name, bubbles, config) {
let target = event.target;
if (target != null) {
let preventDefaultRequests = target.getAttribute(`dioxus-prevent-default`);
let preventDefaultRequests = null;
// Some events can be triggered on text nodes, which don't have attributes
if (target instanceof Element) {
preventDefaultRequests = target.getAttribute(`dioxus-prevent-default`);
}
if (event.type === "click") {
// todo call prevent default if it's the right type of event
@@ -446,15 +450,24 @@ function handler(event, name, bubbles, config) {
target.tagName === "FORM" &&
(event.type === "submit" || event.type === "input")
) {
if (
target.tagName === "FORM" &&
(event.type === "submit" || event.type === "input")
) {
const formData = new FormData(target);
const formData = new FormData(target);
for (let name of formData.keys()) {
let value = formData.getAll(name);
contents.values[name] = value;
for (let name of formData.keys()) {
let value = formData.getAll(name);
contents.values[name] = value;
}
}
if (
target.tagName === "SELECT" &&
event.type === "input"
) {
const selectData = target.options;
contents.values["options"] = [];
for (let i = 0; i < selectData.length; i++) {
let option = selectData[i];
if (option.selected) {
contents.values["options"].push(option.value.toString());
}
}
}
@@ -474,7 +487,10 @@ function handler(event, name, bubbles, config) {
}
function find_real_id(target) {
let realId = target.getAttribute(`data-dioxus-id`);
let realId = null;
if (target instanceof Element) {
realId = target.getAttribute(`data-dioxus-id`);
}
// walk the tree to find the real element
while (realId == null) {
// we've reached the root we don't want to send an event
@@ -483,7 +499,9 @@ function find_real_id(target) {
}
target = target.parentElement;
realId = target.getAttribute(`data-dioxus-id`);
if (target instanceof Element) {
realId = target.getAttribute(`data-dioxus-id`);
}
}
return realId;
}