html_sys/forms/
button.rs

1/// The HTML `<button>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button)
4#[doc(alias = "button")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Button {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Whether the form control is disabled
11    pub disabled: bool,
12    /// Associates the element with a form element
13    pub form: std::option::Option<std::borrow::Cow<'static, str>>,
14    /// URL to use for form submission
15    pub form_action: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Entry list encoding type to use for form submission
17    pub form_enctype: std::option::Option<std::borrow::Cow<'static, str>>,
18    /// Variant to use for form submission
19    pub form_method: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Bypass form control validation for form submission
21    pub form_no_validate: bool,
22    /// Navigable for form submission
23    pub form_target: std::option::Option<std::borrow::Cow<'static, str>>,
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    /// Targets a popover element to toggle, show, or hide
27    pub popovertarget: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Indicates whether a targeted popover element is to be toggled, shown, or hidden
29    pub popovertargetaction: std::option::Option<std::borrow::Cow<'static, str>>,
30    /// Type of button
31    pub type_: std::option::Option<std::borrow::Cow<'static, str>>,
32    /// Value to be used for form submission
33    pub value: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Describes the role(s) the current element plays in the context of the document.
35    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
37    pub aria_active_descendant_element: std::option::Option<
38        std::borrow::Cow<'static, str>,
39    >,
40    /// 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.
41    pub aria_atomic: bool,
42    /// 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.
43    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
44    /// Defines a string value that labels the current element, which is intended to be converted into Braille. See related aria-label.
45    pub aria_braille_label: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// 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.
47    pub aria_braille_role_description: std::option::Option<
48        std::borrow::Cow<'static, str>,
49    >,
50    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
51    pub aria_busy: bool,
52    /// Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. See related aria-pressed and aria-selected.
53    pub aria_checked: std::option::Option<std::borrow::Cow<'static, str>>,
54    /// Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. See related aria-colindextext, aria-colcount, and aria-colspan.
55    pub aria_col_index: std::option::Option<i64>,
56    /// Defines a human readable text alternative of aria-colindex. See related aria-rowindextext.
57    pub aria_col_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
58    /// Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-colindex and aria-rowspan.
59    pub aria_col_span: std::option::Option<i64>,
60    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
61    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
62    /// Indicates the element that represents the current item within a container or set of related elements.
63    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
64    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
65    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
66    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
67    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
68    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
69    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
71    pub aria_disabled: bool,
72    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
73    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
74    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
75    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
76    /// Indicates whether a grouping element owned or controlled by this element is expanded or collapsed.
77    pub aria_expanded: bool,
78    /// 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.
79    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
80    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
81    pub aria_grabbed: bool,
82    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
83    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
84    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
85    pub aria_hidden: bool,
86    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
87    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
88    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
89    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
90    /// Defines a string value that labels the current element. See related aria-labelledby.
91    pub aria_label: std::option::Option<std::borrow::Cow<'static, str>>,
92    /// Identifies the element (or elements) that labels the current element. See related aria-label and aria-describedby.
93    pub aria_labelled_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
94    /// Defines the hierarchical level of an element within a structure.
95    pub aria_level: std::option::Option<i64>,
96    /// 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.
97    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
98    /// Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
99    pub aria_orientation: std::option::Option<std::borrow::Cow<'static, str>>,
100    /// 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.
101    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
102    /// Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-setsize.
103    pub aria_pos_in_set: std::option::Option<i64>,
104    /// Indicates the current "pressed" state of toggle buttons. See related aria-checked and aria-selected.
105    pub aria_pressed: std::option::Option<std::borrow::Cow<'static, str>>,
106    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
107    pub aria_read_only: bool,
108    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
109    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
110    /// Indicates that user input is required on the element before a form can be submitted.
111    pub aria_required: bool,
112    /// Defines a human-readable, author-localized description for the role of an element.
113    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
114    /// Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. See related aria-rowindextext, aria-rowcount, and aria-rowspan.
115    pub aria_row_index: std::option::Option<i64>,
116    /// Defines a human readable text alternative of aria-rowindex. See related aria-colindextext.
117    pub aria_row_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
118    /// Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-rowindex and aria-colspan.
119    pub aria_row_span: std::option::Option<i64>,
120    /// Indicates the current "selected" state of various widgets. See related aria-checked and aria-pressed.
121    pub aria_selected: bool,
122    /// Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-posinset.
123    pub aria_set_size: std::option::Option<i64>,
124    /// Defines the maximum allowed value for a range widget.
125    pub aria_value_max: std::option::Option<f64>,
126    /// Defines the minimum allowed value for a range widget.
127    pub aria_value_min: std::option::Option<f64>,
128    /// Defines the human readable text alternative of aria-valuenow for a range widget.
129    pub aria_value_text: std::option::Option<std::borrow::Cow<'static, str>>,
130}
131impl crate::RenderElement for Button {
132    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
133        write!(writer, "<button")?;
134        if self.disabled {
135            write!(writer, r#" disabled"#)?;
136        }
137        if let Some(field) = self.form.as_ref() {
138            write!(writer, r#" form="{field}""#)?;
139        }
140        if let Some(field) = self.form_action.as_ref() {
141            write!(writer, r#" formaction="{field}""#)?;
142        }
143        if let Some(field) = self.form_enctype.as_ref() {
144            write!(writer, r#" formenctype="{field}""#)?;
145        }
146        if let Some(field) = self.form_method.as_ref() {
147            write!(writer, r#" formmethod="{field}""#)?;
148        }
149        if self.form_no_validate {
150            write!(writer, r#" formnovalidate"#)?;
151        }
152        if let Some(field) = self.form_target.as_ref() {
153            write!(writer, r#" formtarget="{field}""#)?;
154        }
155        if let Some(field) = self.name.as_ref() {
156            write!(writer, r#" name="{field}""#)?;
157        }
158        if let Some(field) = self.popovertarget.as_ref() {
159            write!(writer, r#" popovertarget="{field}""#)?;
160        }
161        if let Some(field) = self.popovertargetaction.as_ref() {
162            write!(writer, r#" popovertargetaction="{field}""#)?;
163        }
164        if let Some(field) = self.type_.as_ref() {
165            write!(writer, r#" type="{field}""#)?;
166        }
167        if let Some(field) = self.value.as_ref() {
168            write!(writer, r#" value="{field}""#)?;
169        }
170        if let Some(field) = self.role.as_ref() {
171            write!(writer, r#" role="{field}""#)?;
172        }
173        if let Some(field) = self.aria_active_descendant_element.as_ref() {
174            write!(writer, r#" aria-activedescendant="{field}""#)?;
175        }
176        if self.aria_atomic {
177            write!(writer, r#" aria-atomic"#)?;
178        }
179        if let Some(field) = self.aria_auto_complete.as_ref() {
180            write!(writer, r#" aria-autocomplete="{field}""#)?;
181        }
182        if let Some(field) = self.aria_braille_label.as_ref() {
183            write!(writer, r#" aria-braillelabel="{field}""#)?;
184        }
185        if let Some(field) = self.aria_braille_role_description.as_ref() {
186            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
187        }
188        if self.aria_busy {
189            write!(writer, r#" aria-busy"#)?;
190        }
191        if let Some(field) = self.aria_checked.as_ref() {
192            write!(writer, r#" aria-checked="{field}""#)?;
193        }
194        if let Some(field) = self.aria_col_index.as_ref() {
195            write!(writer, r#" aria-colindex="{field}""#)?;
196        }
197        if let Some(field) = self.aria_col_index_text.as_ref() {
198            write!(writer, r#" aria-colindextext="{field}""#)?;
199        }
200        if let Some(field) = self.aria_col_span.as_ref() {
201            write!(writer, r#" aria-colspan="{field}""#)?;
202        }
203        if let Some(field) = self.aria_controls_elements.as_ref() {
204            write!(writer, r#" aria-controls="{field}""#)?;
205        }
206        if let Some(field) = self.aria_current.as_ref() {
207            write!(writer, r#" aria-current="{field}""#)?;
208        }
209        if let Some(field) = self.aria_described_by_elements.as_ref() {
210            write!(writer, r#" aria-describedby="{field}""#)?;
211        }
212        if let Some(field) = self.aria_description.as_ref() {
213            write!(writer, r#" aria-description="{field}""#)?;
214        }
215        if let Some(field) = self.aria_details_elements.as_ref() {
216            write!(writer, r#" aria-details="{field}""#)?;
217        }
218        if self.aria_disabled {
219            write!(writer, r#" aria-disabled"#)?;
220        }
221        if let Some(field) = self.aria_drop_effect.as_ref() {
222            write!(writer, r#" aria-dropeffect="{field}""#)?;
223        }
224        if let Some(field) = self.aria_error_message_elements.as_ref() {
225            write!(writer, r#" aria-errormessage="{field}""#)?;
226        }
227        if self.aria_expanded {
228            write!(writer, r#" aria-expanded"#)?;
229        }
230        if let Some(field) = self.aria_flow_to_elements.as_ref() {
231            write!(writer, r#" aria-flowto="{field}""#)?;
232        }
233        if self.aria_grabbed {
234            write!(writer, r#" aria-grabbed"#)?;
235        }
236        if let Some(field) = self.aria_has_popup.as_ref() {
237            write!(writer, r#" aria-haspopup="{field}""#)?;
238        }
239        if self.aria_hidden {
240            write!(writer, r#" aria-hidden"#)?;
241        }
242        if let Some(field) = self.aria_invalid.as_ref() {
243            write!(writer, r#" aria-invalid="{field}""#)?;
244        }
245        if let Some(field) = self.aria_key_shortcuts.as_ref() {
246            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
247        }
248        if let Some(field) = self.aria_label.as_ref() {
249            write!(writer, r#" aria-label="{field}""#)?;
250        }
251        if let Some(field) = self.aria_labelled_by_elements.as_ref() {
252            write!(writer, r#" aria-labelledby="{field}""#)?;
253        }
254        if let Some(field) = self.aria_level.as_ref() {
255            write!(writer, r#" aria-level="{field}""#)?;
256        }
257        if let Some(field) = self.aria_live.as_ref() {
258            write!(writer, r#" aria-live="{field}""#)?;
259        }
260        if let Some(field) = self.aria_orientation.as_ref() {
261            write!(writer, r#" aria-orientation="{field}""#)?;
262        }
263        if let Some(field) = self.aria_owns_elements.as_ref() {
264            write!(writer, r#" aria-owns="{field}""#)?;
265        }
266        if let Some(field) = self.aria_pos_in_set.as_ref() {
267            write!(writer, r#" aria-posinset="{field}""#)?;
268        }
269        if let Some(field) = self.aria_pressed.as_ref() {
270            write!(writer, r#" aria-pressed="{field}""#)?;
271        }
272        if self.aria_read_only {
273            write!(writer, r#" aria-readonly"#)?;
274        }
275        if let Some(field) = self.aria_relevant.as_ref() {
276            write!(writer, r#" aria-relevant="{field}""#)?;
277        }
278        if self.aria_required {
279            write!(writer, r#" aria-required"#)?;
280        }
281        if let Some(field) = self.aria_role_description.as_ref() {
282            write!(writer, r#" aria-roledescription="{field}""#)?;
283        }
284        if let Some(field) = self.aria_row_index.as_ref() {
285            write!(writer, r#" aria-rowindex="{field}""#)?;
286        }
287        if let Some(field) = self.aria_row_index_text.as_ref() {
288            write!(writer, r#" aria-rowindextext="{field}""#)?;
289        }
290        if let Some(field) = self.aria_row_span.as_ref() {
291            write!(writer, r#" aria-rowspan="{field}""#)?;
292        }
293        if self.aria_selected {
294            write!(writer, r#" aria-selected"#)?;
295        }
296        if let Some(field) = self.aria_set_size.as_ref() {
297            write!(writer, r#" aria-setsize="{field}""#)?;
298        }
299        if let Some(field) = self.aria_value_max.as_ref() {
300            write!(writer, r#" aria-valuemax="{field}""#)?;
301        }
302        if let Some(field) = self.aria_value_min.as_ref() {
303            write!(writer, r#" aria-valuemin="{field}""#)?;
304        }
305        if let Some(field) = self.aria_value_text.as_ref() {
306            write!(writer, r#" aria-valuetext="{field}""#)?;
307        }
308        write!(writer, "{}", self.global_attrs)?;
309        write!(writer, "{}", self.data_map)?;
310        write!(writer, ">")?;
311        Ok(())
312    }
313    #[allow(unused_variables)]
314    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
315        write!(writer, "</button>")?;
316        Ok(())
317    }
318}
319impl std::fmt::Display for Button {
320    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
321        use crate::RenderElement;
322        self.write_opening_tag(writer)?;
323        self.write_closing_tag(writer)?;
324        Ok(())
325    }
326}
327impl std::ops::Deref for Button {
328    type Target = crate::GlobalAttributes;
329    fn deref(&self) -> &Self::Target {
330        &self.global_attrs
331    }
332}
333impl std::ops::DerefMut for Button {
334    fn deref_mut(&mut self) -> &mut Self::Target {
335        &mut self.global_attrs
336    }
337}