Skip to main content

dioxus_tw_components/components/
textarea.rs

1use dioxus::prelude::*;
2
3#[derive(Default, Clone, PartialEq, Props)]
4pub struct TextAreaProps {
5    #[props(extends = textarea, extends = GlobalAttributes)]
6    attributes: Vec<Attribute>,
7
8    #[props(optional)]
9    default_value: String,
10
11    #[props(optional)]
12    value: Signal<String>,
13
14    #[props(optional)]
15    onchange: EventHandler<FormEvent>,
16}
17
18#[component]
19pub fn TextArea(mut props: TextAreaProps) -> Element {
20    let default_classes = "textarea";
21    crate::setup_class_attribute(&mut props.attributes, default_classes);
22
23    let oninput = move |event: FormEvent| {
24        props.value.set(event.data.value().clone());
25        props.onchange.call(event);
26    };
27
28    rsx! {
29        textarea {
30            oninput,
31            value: props.default_value,
32            ..props.attributes,
33        }
34    }
35}