Skip to main content

AttributeValue

Enum AttributeValue 

Source
pub enum AttributeValue {
    Text(String),
    Signal(Signal<String>),
    Event(NativeEventHandler),
    Dynamic(String),
    Css(Css),
    InnerHtml(String),
    InnerHtmlSignal(Signal<String>),
    Ref(NodeRefDyn),
}
Expand description

Represents the value of an HTML attribute.

Attributes can be static text, reactive signals, event handlers, dynamic expressions, CSS class references, or raw HTML fragments assigned via inner_html:.

Variants§

§

Text(String)

A static string value.

§

Signal(Signal<String>)

A dynamic signal-backed value.

§

Event(NativeEventHandler)

An event handler callback.

§

Dynamic(String)

A dynamic expression value of any type (for component props).

§

Css(Css)

A CSS class reference created by the class! macro.

§

InnerHtml(String)

A raw HTML fragment assigned via the inner_html: attribute.

Replaces the element’s children wholesale via web_sys::Element::set_inner_html. Unlike Text (which the browser escapes), this variant trusts the input string and runs any embedded <script> tags — it is the euv equivalent of React’s dangerouslySetInnerHTML. Always document the XSS surface when exposing this attribute to user-supplied data.

When both inner_html: and class: / other attributes are set on the same element, inner_html is applied last so it wins on children. Element children listed inside the same html! block are skipped (mirroring React’s behaviour).

§

InnerHtmlSignal(Signal<String>)

A reactive inner_html: payload that re-renders the element’s children whenever the signal value changes.

Same XSS semantics as AttributeValue::InnerHtml — the signal may carry any HTML, including executable <script> tags.

§

Ref(NodeRefDyn)

A reactive handle to the element being created, populated by the renderer after the corresponding ref: attribute fires.

The renderer does not write a ref="..." attribute into the DOM — it intercepts this variant, calls NodeRefDyn::set with the freshly-created element, then clear()s it on unmount.

Implementations§

Source§

impl AttributeValue

Implementation of attribute value factory methods for reactive and merged values.

Source

pub fn reactive<F>(compute: F) -> Self
where F: Fn() -> String + 'static,

Creates a reactive attribute Self for conditional attribute values.

This function replaces the inline Signal::create(...) + subscribe_attr(...) boilerplate that was previously generated by the html! macro for every attribute value containing an if condition.

§Arguments
  • F: Fn() -> String + 'static - A closure that computes the current attribute value. Called on initial render and whenever any signal changes.
§Returns
  • Self - A Self::Signal backed by a Signal<String> that reactively re-evaluates the attribute value on signal updates.
Source

pub fn merge_class(values: &[Self]) -> Self

Merges multiple class attribute values into a single Self.

Each input value is adapted into a Self via IntoReactiveValue. Css values are injected into the DOM and their names are collected. All non-empty class names are joined with spaces into a final Text attribute. If any value is signal-backed, the result becomes a reactive Signal attribute that re-evaluates when any constituent signal changes.

§Arguments
  • &[Self] - The class attribute values to merge.
§Returns
  • Self - A merged attribute value containing space-separated class names.
Source

pub fn merge_style(values: &[Self]) -> Self

Merges multiple style attribute values into a single Self.

Each input value is expected to be a style string (Text) or a reactive Signal<String> producing a style string. All non-empty style strings are joined with spaces into a final combined style attribute. If any value is signal-backed, the result becomes a reactive Signal attribute.

§Arguments
  • &[Self] - The style attribute values to merge.
§Returns
  • Self - A merged attribute value containing the combined CSS style string.

Trait Implementations§

Source§

impl Clone for AttributeValue

Source§

fn clone(&self) -> AttributeValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AttributeValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&'static Css> for AttributeValue

Converts a reference to a CSS class into an attribute value by cloning.

Source§

fn from(css: &'static Css) -> Self

Converts this CSS class reference into an AttributeValue::Css by cloning.

§Returns
  • AttributeValue - A CSS class attribute value.
§Arguments
  • &'static Css - Input value to convert from.
Source§

impl From<&str> for AttributeValue

Converts a string slice into a text attribute value.

Source§

fn from(value: &str) -> Self

Converts this string slice into an AttributeValue::Text.

§Returns
  • AttributeValue - A text attribute value containing the owned string.
§Arguments
  • &str - Input value to convert from.
Source§

impl<T> From<AttrValueAdapter<T>> for AttributeValue
where T: Into<AttributeValue>,

Adapts any type that implements Into<AttributeValue> into an AttributeValue.

This is the fallback path for non-closure attribute values (strings, signals, CSS classes, etc.).

Source§

fn from(adapter: AttrValueAdapter<T>) -> Self

Converts the wrapped value into an AttributeValue.

§Returns
  • AttributeValue - The reactive attribute value.
§Arguments
  • AttrValueAdapter<T> - Input value to convert from.
Source§

impl<F> From<CallbackNamedAdapter<F>> for AttributeValue
where F: FnMut(Event) + 'static,

Converts a named callback adapter into an AttributeValue.

Source§

fn from(adapter: CallbackNamedAdapter<F>) -> Self

Converts the wrapped closure with custom name into a callback AttributeValue.

§Returns
  • AttributeValue - An event attribute value with the custom name.
§Arguments
  • CallbackNamedAdapter<F> - Input value to convert from.
Source§

impl From<Css> for AttributeValue

Converts a CSS class reference into an attribute value.

Source§

fn from(css: Css) -> Self

Converts this CSS class into an AttributeValue::Css.

§Returns
  • AttributeValue - A CSS class attribute value.
§Arguments
  • Css - Input value to convert from.
Source§

impl<F> From<EventNamedAdapter<F>> for AttributeValue
where F: FnMut(Event) + 'static,

Converts an event with a specific event name into an AttributeValue.

Source§

fn from(adapter: EventNamedAdapter<F>) -> Self

Converts the wrapped closure with event name into an event AttributeValue.

§Returns
  • AttributeValue - An AttributeValue::Event wrapping the handler.
§Arguments
  • EventNamedAdapter<F> - Input value to convert from.
Source§

impl From<EventNamedAdapter<NativeEventHandler>> for AttributeValue

Converts an event named adapter with NativeEventHandler into an AttributeValue.

Source§

fn from(adapter: EventNamedAdapter<NativeEventHandler>) -> Self

Converts the wrapped handler with event name into an event AttributeValue.

§Returns
  • AttributeValue - An AttributeValue::Event wrapping the handler.
§Arguments
  • EventNamedAdapter<NativeEventHandler> - Input value to convert from.
Source§

impl From<EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>> for AttributeValue

Converts an event named adapter with optional shared closure into an AttributeValue.

Some(callback) becomes AttributeValue::Event by wrapping the shared closure into a NativeEventHandler with the adapter’s event name, and None becomes AttributeValue::Text(String::new()).

Source§

fn from(adapter: EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>) -> Self

Converts the wrapped optional shared closure with event name into an event AttributeValue.

§Returns
  • AttributeValue - An event attribute if Some, otherwise an empty text attribute.
§Arguments
  • EventNamedAdapter<Option<Rc<dyn Fn(Event)>>> - Input value to convert from.
Source§

impl<F> From<F> for AttributeValue
where F: FnMut(Event) + 'static,

Converts a closure into a callback attribute value.

Source§

fn from(closure: F) -> Self

Wraps this closure into an AttributeValue::Event with a generic “callback” event name.

§Returns
  • AttributeValue - An event attribute value wrapping this closure.
§Arguments
  • F - Input value to convert from.
Source§

impl From<InnerHtmlAdapter<&str>> for AttributeValue

From conversion into AttributeValue.

Source§

fn from(adapter: InnerHtmlAdapter<&str>) -> Self

Wraps the static &str payload by allocating a new String so the renderer owns the data independently of the caller’s borrow lifetime.

§Arguments
  • InnerHtmlAdapter<&str> - Input value to convert from.
Source§

impl From<InnerHtmlAdapter<Signal<String>>> for AttributeValue

From conversion into AttributeValue.

Source§

fn from(adapter: InnerHtmlAdapter<Signal<String>>) -> Self

Wraps the reactive payload in an AttributeValue::InnerHtmlSignal so the renderer subscribes to the signal and re-applies set_inner_html on every change.

§Arguments
  • InnerHtmlAdapter<Signal<String>> - Input value to convert from.
Source§

impl From<InnerHtmlAdapter<String>> for AttributeValue

Adapts an inner_html: payload into the matching AttributeValue variant, routing through set_inner_html instead of the generic Text attribute path.

The two blanket impls below cover the user-visible call sites:

  • String produces AttributeValue::InnerHtml(String::from("...")).
  • Signal<String> produces AttributeValue::InnerHtmlSignal(signal).

Each impl only requires its specific source type, so the compiler picks the right one based on the inferred T at the call site (no manual .into() annotation needed).

Source§

fn from(adapter: InnerHtmlAdapter<String>) -> Self

Wraps the static String payload in an AttributeValue::InnerHtml variant so the renderer can call Element::set_inner_html on it.

§Arguments
  • InnerHtmlAdapter<String> - Input value to convert from.
Source§

impl From<NativeEventHandler> for AttributeValue

Converts an owned event handler into a callback attribute value.

Re-wraps the handler with a generic “callback” event name so that subsequent EventAdapter::into_attribute calls can override it with the correct DOM event type.

Source§

fn from(handler: NativeEventHandler) -> Self

Converts this event handler into an AttributeValue::Event.

§Returns
  • AttributeValue - An event attribute value with a generic callback event name.
§Arguments
  • NativeEventHandler - Input value to convert from.
Source§

impl<T: ?Sized> From<NodeRef<T>> for AttributeValue

Converts a NodeRef<T> into an AttributeValue::Ref.

The type parameter T is erased at the AttributeValue layer (we store the underlying JsValue cell), so any concrete element type works. The html! macro relies on this to accept html! { input { ref: my_ref } } without the user needing to call .into() explicitly.

Source§

fn from(node_ref: NodeRef<T>) -> Self

Wraps the ref cell as an AttributeValue::Ref so the renderer can populate it after mount.

§Returns
  • AttributeValue - A ref variant carrying the (still empty) handle.
§Arguments
  • NodeRef<T> - Input value to convert from.
Source§

impl From<Option<NativeEventHandler>> for AttributeValue

Converts an optional event handler into a callback attribute value.

Re-wraps a Some handler with a generic “callback” event name so that subsequent EventAdapter::into_attribute calls can override it with the correct DOM event type.

Source§

fn from(handler: Option<NativeEventHandler>) -> Self

Converts this optional handler into an AttributeValue::Event or AttributeValue::Text if None.

§Returns
  • AttributeValue - An event attribute value if Some, otherwise an empty text attribute.
§Arguments
  • Option<NativeEventHandler> - Input value to convert from.
Source§

impl From<Option<Signal<String>>> for AttributeValue

Converts an optional string signal into a reactive or empty attribute value.

Some(signal) becomes AttributeValue::Signal, None becomes AttributeValue::Text(String::new()). This supports component props that use Option<Signal<String>> for optional reactive attributes.

Source§

fn from(signal: Option<Signal<String>>) -> Self

Converts this optional signal into an AttributeValue::Signal or AttributeValue::Text if None.

§Returns
  • AttributeValue - A signal-backed attribute value if Some, otherwise an empty text attribute.
§Arguments
  • Option<Signal<String>> - Input value to convert from.
Source§

impl From<Signal<String>> for AttributeValue

Converts a string signal into a reactive attribute value.

Source§

fn from(signal: Signal<String>) -> Self

Converts this string signal into an AttributeValue::Signal.

§Returns
  • AttributeValue - A signal-backed attribute value.
§Arguments
  • Signal<String> - Input value to convert from.
Source§

impl From<Signal<bool>> for AttributeValue

Converts a mutable bool signal into a reactive attribute value.

The signal is mapped to a Signal<String> that yields "true" or "false", enabling boolean attributes like checked to reactively update the DOM.

Source§

fn from(signal: Signal<bool>) -> Self

Converts this bool signal into an AttributeValue via string mapping.

§Returns
  • AttributeValue - A signal-backed attribute value yielding "true" or "false".
§Arguments
  • Signal<bool> - Input value to convert from.
Source§

impl From<String> for AttributeValue

Converts a static String into a text attribute value.

Source§

fn from(value: String) -> Self

Converts this string into an AttributeValue::Text.

§Returns
  • AttributeValue - A text attribute value containing this string.
§Arguments
  • String - Input value to convert from.
Source§

impl From<bool> for AttributeValue

Converts a bool into a dynamic attribute value.

Stored as AttributeValue::Dynamic("true"/"false") so components can extract the original boolean via try_get_typed_prop.

Source§

fn from(value: bool) -> Self

Converts this boolean into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the boolean string.
§Arguments
  • bool - Input value to convert from.
Source§

impl From<f64> for AttributeValue

Converts an f64 into a dynamic attribute value.

Stored as AttributeValue::Dynamic so components can extract the original float via try_get_typed_prop.

Source§

fn from(value: f64) -> Self

Converts this float into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the float string.
§Arguments
  • f64 - Input value to convert from.
Source§

impl From<i32> for AttributeValue

Converts an i32 into a dynamic attribute value.

Stored as AttributeValue::Dynamic so components can extract the original integer via try_get_typed_prop.

Source§

fn from(value: i32) -> Self

Converts this integer into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the integer string.
§Arguments
  • i32 - Input value to convert from.
Source§

impl PartialEq for AttributeValue

Visual equality comparison for attribute values.

Compares values by their visual output rather than identity. Signal values are compared by their current resolved string; when both signals share the same inner pointer, they are always considered unequal because the signal may have mutated between VDOM snapshots and .get() would return the same current value for both, masking the change. Event values are always considered equal (re-binding is handled by the handler registry), and Css values are compared by class name.

Source§

fn eq(&self, other: &Self) -> bool

Compares two attribute values for visual equality.

§Arguments
  • &Self - The first attribute value.
  • &Self - The second attribute value.
§Returns
  • bool - true if the values are visually equal.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more