Skip to main content

ElementExt

Trait ElementExt 

Source
pub trait ElementExt {
    // Required methods
    fn attr<At>(&self, attribute: At) -> <At as Attribute>::State
       where At: Attribute;
    fn class<C>(&self, class: C) -> <C as IntoClass>::State
       where C: IntoClass;
    fn style<S>(&self, style: S) -> <S as IntoStyle>::State
       where S: IntoStyle;
    fn on<E>(
        &self,
        ev: E,
        cb: impl FnMut(<E as EventDescriptor>::EventType) + 'static,
    ) -> RemoveEventHandler<Element>
       where E: EventDescriptor + Send + 'static,
             <E as EventDescriptor>::EventType: 'static + From<JsValue>;
}
Expand description

Extends an HTML element, allowing you to add attributes and children to the element’s built state at runtime, with a similar API to how they can be added to the static view tree at compile time.

use tachys::html::element::ElementExt;

let view: HtmlElement<_, _, _, MockDom> = button();

// add an event listener as part of the static type
// this will be lazily added when the element is built
let view = element.on(ev::click, move |_| /* ... */);

// `element` now contains the actual element
let element = element.build();
let remove = element.on(ev::blur, move |_| /* ... */);

Required Methods§

Source

fn attr<At>(&self, attribute: At) -> <At as Attribute>::State
where At: Attribute,

Adds an attribute to the element, at runtime.

Source

fn class<C>(&self, class: C) -> <C as IntoClass>::State
where C: IntoClass,

Adds a class to the element, at runtime.

Source

fn style<S>(&self, style: S) -> <S as IntoStyle>::State
where S: IntoStyle,

Adds a style to the element, at runtime.

Source

fn on<E>( &self, ev: E, cb: impl FnMut(<E as EventDescriptor>::EventType) + 'static, ) -> RemoveEventHandler<Element>
where E: EventDescriptor + Send + 'static, <E as EventDescriptor>::EventType: 'static + From<JsValue>,

Adds an event listener to the element, at runtime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ElementExt for T
where T: AsRef<Element>,