dioxus_native_core::custom_element

Trait CustomElement

Source
pub trait CustomElement<V: FromAnyValue + Send + Sync = ()>:
    Send
    + Sync
    + 'static {
    const NAME: &'static str;
    const NAMESPACE: Option<&'static str> = None;

    // Required methods
    fn create(light_root: NodeMut<'_, V>) -> Self;
    fn roots(&self) -> Vec<NodeId>;
    fn attributes_changed(
        &mut self,
        light_node: NodeMut<'_, V>,
        attributes: &AttributeMask,
    );

    // Provided method
    fn slot(&self) -> Option<NodeId> { ... }
}
Expand description

A controlled element that renders to a shadow DOM.

Register with RealDom::register_custom_element

This is a simplified custom element trait for elements that can create themselves. For more granular control, implement CustomElementFactory and CustomElementUpdater instead.

Required Associated Constants§

Source

const NAME: &'static str

The tag of the element

Provided Associated Constants§

Source

const NAMESPACE: Option<&'static str> = None

The namespace of the element

Required Methods§

Source

fn create(light_root: NodeMut<'_, V>) -> Self

Create a new element without mounting it. The node passed in is the light DOM node. The element should not modify the light DOM node, but it can get the NodeMut::real_dom_mut from the node to create new nodes.

Source

fn roots(&self) -> Vec<NodeId>

The root node of the custom element. These roots must be not change once the element is created.

Source

fn attributes_changed( &mut self, light_node: NodeMut<'_, V>, attributes: &AttributeMask, )

Update the custom element’s shadow tree with the new attributes. Called when the attributes of the custom element are changed.

Provided Methods§

Source

fn slot(&self) -> Option<NodeId>

The slot to render children of the element into. The slot must be not change once the element is created.

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§