Added dynatos_html::ElementWithInnerHtml.

This commit is contained in:
Filipe Rodrigues 2024-12-03 04:24:55 +00:00
parent 352467ba41
commit df9d973af3
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU

View File

@ -24,6 +24,22 @@ where
}
}
/// Extension trait to set the inner html in a builder-style.
#[extend::ext_sized(name = ElementWithInnerHtml)]
pub impl<T> T
where
T: AsRef<web_sys::Element>,
{
fn with_inner_html<C>(self, html: C) -> Self
where
C: AsTextContent,
{
// TODO: Is a default of `""` fine here?
self.as_ref().set_inner_html(html.as_text().unwrap_or(""));
self
}
}
/// Types that may be used for [`NodeWithText`]
pub trait AsTextContent {
/// Returns the text