patternfly_yew/utils/html.rs
1use web_sys::HtmlInputElement;
2use yew::NodeRef;
3
4// TODO: remove this in the next version
5pub use web_tools::{
6 iter::{IterableHtmlCollection, IterableNodeList},
7 optimistic::{
8 OptimisticElement as ElementSupport, OptimisticHtmlElement as HtmlElementSupport,
9 },
10};
11
12/// Focus an HTML input element.
13///
14/// The ref must point to an [`web_sys::HtmlElement`], if it does not, the function does nothing.
15pub fn focus(node_ref: &NodeRef) {
16 node_ref.focus();
17}
18
19/// Retrieve the value of an [`HtmlInputElement`].
20///
21/// The ref must point to an [`HtmlInputElement`], if it does not, the function will return [`None`].
22pub fn value(node_ref: &NodeRef) -> Option<String> {
23 node_ref
24 .cast::<HtmlInputElement>()
25 .map(|input| input.value())
26}