[][src]Struct yew::html::NodeRef

pub struct NodeRef(_);

Wrapped Node reference for later use in Component lifecycle methods.

Example

Focus an <input> element on mount.

#[cfg(feature = "std_web")]
use stdweb::web::{html_element::InputElement, IHtmlElement};
#[cfg(feature = "web_sys")]
use web_sys::HtmlInputElement as InputElement;

pub struct Input {
    node_ref: NodeRef,
}

impl Component for Input {
    type Message = ();
    type Properties = ();

    fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
        Input {
            node_ref: NodeRef::default(),
        }
    }

    fn rendered(&mut self, first_render: bool) {
        if first_render {
            if let Some(input) = self.node_ref.cast::<InputElement>() {
                input.focus();
            }
        }
    }

    fn change(&mut self, _: Self::Properties) -> ShouldRender {
        false
    }

    fn update(&mut self, _: Self::Message) -> ShouldRender {
        false
    }

    fn view(&self) -> Html {
        html! {
            <input ref=self.node_ref.clone() type="text" />
        }
    }
}

Implementations

impl NodeRef[src]

pub fn get(&self) -> Option<Node>[src]

Get the wrapped Node reference if it exists

pub fn cast<INTO: AsRef<Node> + From<JsValue>>(&self) -> Option<INTO>[src]

Try converting the node reference into another form

Trait Implementations

impl Clone for NodeRef[src]

impl Debug for NodeRef[src]

impl Default for NodeRef[src]

impl PartialEq<NodeRef> for NodeRef[src]

Auto Trait Implementations

impl !RefUnwindSafe for NodeRef

impl !Send for NodeRef

impl !Sync for NodeRef

impl Unpin for NodeRef

impl !UnwindSafe for NodeRef

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.