fix: event delegation issue with `<input name="host">` (#1332)

This commit is contained in:
Greg Johnston 2023-07-12 16:20:11 -04:00 committed by GitHub
parent a0fae88f7d
commit d4b1ceda90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -49,6 +49,7 @@ features = [
"Range",
"Text",
"HtmlCollection",
"ShadowRoot",
"TreeWalker",
# Events we cast to in leptos_macro -- added here so we don't force users to import them

View File

@ -158,19 +158,13 @@ pub(crate) fn add_delegated_event_listener(
}
// navigate up tree
let host =
js_sys::Reflect::get(&node, &JsValue::from_str("host"))
.unwrap_throw();
if host.is_truthy()
&& host != node
&& host.dyn_ref::<web_sys::Node>().is_some()
{
node = host;
} else if let Some(parent) =
node.unchecked_into::<web_sys::Node>().parent_node()
if let Some(parent) =
node.unchecked_ref::<web_sys::Node>().parent_node()
{
node = parent.into()
} else {
} else if let Some(root) = node.dyn_ref::<web_sys::ShadowRoot>() {
node = root.host().unchecked_into();
} else {
node = JsValue::null()
}
}