Struct leptos_dom::html::HtmlElement
source · pub struct HtmlElement<El: ElementDescriptor> { /* private fields */ }
Expand description
Represents an HTML element.
Implementations§
source§impl<El: ElementDescriptor + 'static> HtmlElement<El>
impl<El: ElementDescriptor + 'static> HtmlElement<El>
sourcepub fn with_view_marker(self, marker: impl Into<String>) -> Self
pub fn with_view_marker(self, marker: impl Into<String>) -> Self
Adds an optional marker indicating the view macro source.
sourcepub fn into_any(self) -> HtmlElement<AnyElement>
pub fn into_any(self) -> HtmlElement<AnyElement>
Converts this element into HtmlElement<AnyElement>
.
sourcepub fn node_ref(self, node_ref: NodeRef<El>) -> Selfwhere
Self: Clone,
pub fn node_ref(self, node_ref: NodeRef<El>) -> Selfwhere
Self: Clone,
Binds the element reference to NodeRef
.
sourcepub fn on_mount(self, f: impl FnOnce(Self) + 'static) -> Self
pub fn on_mount(self, f: impl FnOnce(Self) + 'static) -> Self
Runs the callback when this element has been mounted to the DOM.
§Important Note
This method will only ever run at most once. If this element is unmounted and remounted, or moved somewhere else, it will not re-run unless you call this method again.
sourcepub fn is_mounted(&self) -> bool
pub fn is_mounted(&self) -> bool
Checks to see if this element is mounted to the DOM as a child
of body
.
This method will always return false
on non-wasm CSR targets.
sourcepub fn attr(
self,
name: impl Into<Oco<'static, str>>,
attr: impl IntoAttribute
) -> Self
pub fn attr( self, name: impl Into<Oco<'static, str>>, attr: impl IntoAttribute ) -> Self
Adds an attribute to this element.
sourcepub fn attrs(
self,
attrs: impl IntoIterator<Item = (&'static str, Attribute)>
) -> Self
pub fn attrs( self, attrs: impl IntoIterator<Item = (&'static str, Attribute)> ) -> Self
Adds multiple attributes to the element.
sourcepub fn bindings<B: Into<Binding>>(
self,
bindings: impl IntoIterator<Item = B>
) -> Self
pub fn bindings<B: Into<Binding>>( self, bindings: impl IntoIterator<Item = B> ) -> Self
Adds multiple bindings (attributes or event handlers) to the element.
sourcepub fn class(
self,
name: impl Into<Oco<'static, str>>,
class: impl IntoClass
) -> Self
pub fn class( self, name: impl Into<Oco<'static, str>>, class: impl IntoClass ) -> Self
Adds a class to an element.
Note: In the builder syntax, this will be overwritten by the class
attribute if you use .attr("class", /* */)
. In the view
macro, they
are automatically re-ordered so that this over-writing does not happen.
§Panics
This directly uses the browser’s classList
API, which means it will throw
a runtime error if you pass more than a single class name. If you want to
pass more than one class name at a time, you can use HtmlElement::classes.
sourcepub fn classes(self, classes: impl Into<Oco<'static, str>>) -> Self
pub fn classes(self, classes: impl Into<Oco<'static, str>>) -> Self
Adds a list of classes separated by ASCII whitespace to an element.
sourcepub fn dyn_classes<I, C>(self, classes_signal: impl Fn() -> I + 'static) -> Self
pub fn dyn_classes<I, C>(self, classes_signal: impl Fn() -> I + 'static) -> Self
Sets the class on the element as the class signal changes.
sourcepub fn style(
self,
name: impl Into<Oco<'static, str>>,
style: impl IntoStyle
) -> Self
pub fn style( self, name: impl Into<Oco<'static, str>>, style: impl IntoStyle ) -> Self
Sets a style on an element.
Note: In the builder syntax, this will be overwritten by the style
attribute if you use .attr("style", /* */)
. In the view
macro, they
are automatically re-ordered so that this over-writing does not happen.
sourcepub fn prop(
self,
name: impl Into<Oco<'static, str>>,
value: impl IntoProperty
) -> Self
pub fn prop( self, name: impl Into<Oco<'static, str>>, value: impl IntoProperty ) -> Self
Sets a property on an element.
sourcepub fn on<E: EventDescriptor + 'static>(
self,
event: E,
event_handler: impl FnMut(E::EventType) + 'static
) -> Self
pub fn on<E: EventDescriptor + 'static>( self, event: E, event_handler: impl FnMut(E::EventType) + 'static ) -> Self
Adds an event listener to this element.
sourcepub fn optional_event<E: EventDescriptor + 'static>(
self,
event: E,
event_handler: Option<impl FnMut(E::EventType) + 'static>
) -> Self
pub fn optional_event<E: EventDescriptor + 'static>( self, event: E, event_handler: Option<impl FnMut(E::EventType) + 'static> ) -> Self
Optionally adds an event listener to this element.
§Example
#[component]
pub fn Input(
#[prop(optional)] value: Option<RwSignal<String>>,
) -> impl IntoView {
view! { <input/> }
// only add event if `value` is `Some(signal)`
.optional_event(
ev::input,
value.map(|value| move |ev| value.set(event_target_value(&ev))),
)
}
source§impl<El: ElementDescriptor + Clone + 'static> HtmlElement<El>
impl<El: ElementDescriptor + Clone + 'static> HtmlElement<El>
Trait Implementations§
source§impl<El: Clone + ElementDescriptor> Clone for HtmlElement<El>
impl<El: Clone + ElementDescriptor> Clone for HtmlElement<El>
source§fn clone(&self) -> HtmlElement<El>
fn clone(&self) -> HtmlElement<El>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T> DOMEventResponder for HtmlElement<T>where
T: ElementDescriptor + 'static,
impl<T> DOMEventResponder for HtmlElement<T>where
T: ElementDescriptor + 'static,
source§fn add<E: EventDescriptor + 'static>(
self,
event: E,
handler: impl FnMut(E::EventType) + 'static
) -> Self
fn add<E: EventDescriptor + 'static>( self, event: E, handler: impl FnMut(E::EventType) + 'static ) -> Self
source§fn add_handler(self, handler: impl EventHandler) -> Self
fn add_handler(self, handler: impl EventHandler) -> Self
EventHandler