html_sys/forms/
textarea.rs

1/// The HTML `<textarea>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)
4#[doc(alias = "textarea")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct TextArea {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Hint for form autofill feature
11    pub autocomplete: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// Maximum number of characters per line
13    pub cols: std::option::Option<i64>,
14    /// Name of form control to use for sending the element's directionality in form submission
15    pub dir_name: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Whether the form control is disabled
17    pub disabled: bool,
18    /// Associates the element with a form element
19    pub form: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Maximum length of value
21    pub max_length: std::option::Option<i64>,
22    /// Minimum length of value
23    pub min_length: std::option::Option<i64>,
24    /// Name of the element to use for form submission and in the form.elements API
25    pub name: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// User-visible label to be placed within the form control
27    pub placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Whether to allow the value to be edited by the user
29    pub read_only: bool,
30    /// Whether the control is required for form submission
31    pub required: bool,
32    /// Number of lines to show
33    pub rows: std::option::Option<i64>,
34    /// How the value of the form control is to be wrapped for form submission
35    pub wrap: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// Describes the role(s) the current element plays in the context of the document.
37    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
38    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
39    pub aria_active_descendant_element: std::option::Option<
40        std::borrow::Cow<'static, str>,
41    >,
42    /// Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
43    pub aria_atomic: bool,
44    /// Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for a combobox, searchbox, or textbox and specifies how predictions would be presented if they were made.
45    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Defines a string value that labels the current element, which is intended to be converted into Braille. See related aria-label.
47    pub aria_braille_label: std::option::Option<std::borrow::Cow<'static, str>>,
48    /// Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. See related aria-roledescription.
49    pub aria_braille_role_description: std::option::Option<
50        std::borrow::Cow<'static, str>,
51    >,
52    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
53    pub aria_busy: bool,
54    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
55    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
56    /// Indicates the element that represents the current item within a container or set of related elements.
57    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
58    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
59    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
60    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
61    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
62    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
63    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
64    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
65    pub aria_disabled: bool,
66    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
67    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
68    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
69    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
71    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
72    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
73    pub aria_grabbed: bool,
74    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
75    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
76    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
77    pub aria_hidden: bool,
78    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
79    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
80    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
81    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
82    /// Defines a string value that labels the current element. See related aria-labelledby.
83    pub aria_label: std::option::Option<std::borrow::Cow<'static, str>>,
84    /// Identifies the element (or elements) that labels the current element. See related aria-label and aria-describedby.
85    pub aria_labelled_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
86    /// Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
87    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
88    /// Indicates whether a text box accepts multiple lines of input or only a single line.
89    pub aria_multi_line: bool,
90    /// Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. See related aria-controls.
91    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
92    /// Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
93    pub aria_placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
94    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
95    pub aria_read_only: bool,
96    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
97    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
98    /// Indicates that user input is required on the element before a form can be submitted.
99    pub aria_required: bool,
100    /// Defines a human-readable, author-localized description for the role of an element.
101    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
102}
103impl crate::RenderElement for TextArea {
104    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
105        write!(writer, "<textarea")?;
106        if let Some(field) = self.autocomplete.as_ref() {
107            write!(writer, r#" autocomplete="{field}""#)?;
108        }
109        if let Some(field) = self.cols.as_ref() {
110            write!(writer, r#" cols="{field}""#)?;
111        }
112        if let Some(field) = self.dir_name.as_ref() {
113            write!(writer, r#" dirname="{field}""#)?;
114        }
115        if self.disabled {
116            write!(writer, r#" disabled"#)?;
117        }
118        if let Some(field) = self.form.as_ref() {
119            write!(writer, r#" form="{field}""#)?;
120        }
121        if let Some(field) = self.max_length.as_ref() {
122            write!(writer, r#" maxlength="{field}""#)?;
123        }
124        if let Some(field) = self.min_length.as_ref() {
125            write!(writer, r#" minlength="{field}""#)?;
126        }
127        if let Some(field) = self.name.as_ref() {
128            write!(writer, r#" name="{field}""#)?;
129        }
130        if let Some(field) = self.placeholder.as_ref() {
131            write!(writer, r#" placeholder="{field}""#)?;
132        }
133        if self.read_only {
134            write!(writer, r#" readonly"#)?;
135        }
136        if self.required {
137            write!(writer, r#" required"#)?;
138        }
139        if let Some(field) = self.rows.as_ref() {
140            write!(writer, r#" rows="{field}""#)?;
141        }
142        if let Some(field) = self.wrap.as_ref() {
143            write!(writer, r#" wrap="{field}""#)?;
144        }
145        if let Some(field) = self.role.as_ref() {
146            write!(writer, r#" role="{field}""#)?;
147        }
148        if let Some(field) = self.aria_active_descendant_element.as_ref() {
149            write!(writer, r#" aria-activedescendant="{field}""#)?;
150        }
151        if self.aria_atomic {
152            write!(writer, r#" aria-atomic"#)?;
153        }
154        if let Some(field) = self.aria_auto_complete.as_ref() {
155            write!(writer, r#" aria-autocomplete="{field}""#)?;
156        }
157        if let Some(field) = self.aria_braille_label.as_ref() {
158            write!(writer, r#" aria-braillelabel="{field}""#)?;
159        }
160        if let Some(field) = self.aria_braille_role_description.as_ref() {
161            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
162        }
163        if self.aria_busy {
164            write!(writer, r#" aria-busy"#)?;
165        }
166        if let Some(field) = self.aria_controls_elements.as_ref() {
167            write!(writer, r#" aria-controls="{field}""#)?;
168        }
169        if let Some(field) = self.aria_current.as_ref() {
170            write!(writer, r#" aria-current="{field}""#)?;
171        }
172        if let Some(field) = self.aria_described_by_elements.as_ref() {
173            write!(writer, r#" aria-describedby="{field}""#)?;
174        }
175        if let Some(field) = self.aria_description.as_ref() {
176            write!(writer, r#" aria-description="{field}""#)?;
177        }
178        if let Some(field) = self.aria_details_elements.as_ref() {
179            write!(writer, r#" aria-details="{field}""#)?;
180        }
181        if self.aria_disabled {
182            write!(writer, r#" aria-disabled"#)?;
183        }
184        if let Some(field) = self.aria_drop_effect.as_ref() {
185            write!(writer, r#" aria-dropeffect="{field}""#)?;
186        }
187        if let Some(field) = self.aria_error_message_elements.as_ref() {
188            write!(writer, r#" aria-errormessage="{field}""#)?;
189        }
190        if let Some(field) = self.aria_flow_to_elements.as_ref() {
191            write!(writer, r#" aria-flowto="{field}""#)?;
192        }
193        if self.aria_grabbed {
194            write!(writer, r#" aria-grabbed"#)?;
195        }
196        if let Some(field) = self.aria_has_popup.as_ref() {
197            write!(writer, r#" aria-haspopup="{field}""#)?;
198        }
199        if self.aria_hidden {
200            write!(writer, r#" aria-hidden"#)?;
201        }
202        if let Some(field) = self.aria_invalid.as_ref() {
203            write!(writer, r#" aria-invalid="{field}""#)?;
204        }
205        if let Some(field) = self.aria_key_shortcuts.as_ref() {
206            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
207        }
208        if let Some(field) = self.aria_label.as_ref() {
209            write!(writer, r#" aria-label="{field}""#)?;
210        }
211        if let Some(field) = self.aria_labelled_by_elements.as_ref() {
212            write!(writer, r#" aria-labelledby="{field}""#)?;
213        }
214        if let Some(field) = self.aria_live.as_ref() {
215            write!(writer, r#" aria-live="{field}""#)?;
216        }
217        if self.aria_multi_line {
218            write!(writer, r#" aria-multiline"#)?;
219        }
220        if let Some(field) = self.aria_owns_elements.as_ref() {
221            write!(writer, r#" aria-owns="{field}""#)?;
222        }
223        if let Some(field) = self.aria_placeholder.as_ref() {
224            write!(writer, r#" aria-placeholder="{field}""#)?;
225        }
226        if self.aria_read_only {
227            write!(writer, r#" aria-readonly"#)?;
228        }
229        if let Some(field) = self.aria_relevant.as_ref() {
230            write!(writer, r#" aria-relevant="{field}""#)?;
231        }
232        if self.aria_required {
233            write!(writer, r#" aria-required"#)?;
234        }
235        if let Some(field) = self.aria_role_description.as_ref() {
236            write!(writer, r#" aria-roledescription="{field}""#)?;
237        }
238        write!(writer, "{}", self.global_attrs)?;
239        write!(writer, "{}", self.data_map)?;
240        write!(writer, ">")?;
241        Ok(())
242    }
243    #[allow(unused_variables)]
244    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
245        write!(writer, "</textarea>")?;
246        Ok(())
247    }
248}
249impl std::fmt::Display for TextArea {
250    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
251        use crate::RenderElement;
252        self.write_opening_tag(writer)?;
253        self.write_closing_tag(writer)?;
254        Ok(())
255    }
256}
257impl std::ops::Deref for TextArea {
258    type Target = crate::GlobalAttributes;
259    fn deref(&self) -> &Self::Target {
260        &self.global_attrs
261    }
262}
263impl std::ops::DerefMut for TextArea {
264    fn deref_mut(&mut self) -> &mut Self::Target {
265        &mut self.global_attrs
266    }
267}