use web_sys::wasm_bindgen::JsCast;
pub trait OptimisticHtmlInputElement {
fn form(&self) -> Option<web_sys::HtmlFormElement>;
fn checked(&self) -> bool;
}
impl OptimisticHtmlInputElement for web_sys::Node {
fn form(&self) -> Option<web_sys::HtmlFormElement> {
self.dyn_ref::<web_sys::HtmlInputElement>()
.and_then(|input| input.form())
}
fn checked(&self) -> bool {
self.dyn_ref::<web_sys::HtmlInputElement>()
.map(|input| input.checked())
.unwrap_or_default()
}
}
#[cfg(feature = "yew")]
impl OptimisticHtmlInputElement for yew::prelude::NodeRef {
fn form(&self) -> Option<web_sys::HtmlFormElement> {
self.cast::<web_sys::HtmlInputElement>()
.and_then(|input| input.form())
}
fn checked(&self) -> bool {
self.cast::<web_sys::HtmlInputElement>()
.map(|input| input.checked())
.unwrap_or_default()
}
}