Skip to main content

orbital_base_components/form/input/
ref.rs

1use leptos::{html, prelude::*};
2
3#[derive(Clone)]
4pub struct InputRef {
5    pub(crate) input_ref: NodeRef<html::Input>,
6}
7
8impl InputRef {
9    pub fn new(input_ref: NodeRef<html::Input>) -> Self {
10        Self { input_ref }
11    }
12
13    pub fn focus(&self) {
14        if let Some(input_el) = self.input_ref.get_untracked() {
15            _ = input_el.focus();
16        }
17    }
18
19    pub fn blur(&self) {
20        if let Some(input_el) = self.input_ref.get_untracked() {
21            _ = input_el.blur();
22        }
23    }
24
25    pub fn select(&self) {
26        if let Some(input_el) = self.input_ref.get_untracked() {
27            input_el.select();
28        }
29    }
30}