html_sys/forms/
select.rs

1/// The HTML `<select>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)
4#[doc(alias = "select")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Select {
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    /// Whether the form control is disabled
13    pub disabled: bool,
14    /// Associates the element with a form element
15    pub form: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Whether to allow multiple values
17    pub multiple: bool,
18    /// Name of the element to use for form submission and in the form.elements API
19    pub name: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Whether the control is required for form submission
21    pub required: bool,
22    /// Size of the control
23    pub size: std::option::Option<i64>,
24    /// Describes the role(s) the current element plays in the context of the document.
25    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
27    pub aria_active_descendant_element: std::option::Option<
28        std::borrow::Cow<'static, str>,
29    >,
30    /// 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.
31    pub aria_atomic: bool,
32    /// 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.
33    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Defines a string value that labels the current element, which is intended to be converted into Braille. See related aria-label.
35    pub aria_braille_label: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// 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.
37    pub aria_braille_role_description: std::option::Option<
38        std::borrow::Cow<'static, str>,
39    >,
40    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
41    pub aria_busy: bool,
42    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
43    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
44    /// Indicates the element that represents the current item within a container or set of related elements.
45    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
47    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
48    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
49    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
50    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
51    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
52    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
53    pub aria_disabled: bool,
54    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
55    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
56    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
57    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
58    /// Indicates whether a grouping element owned or controlled by this element is expanded or collapsed.
59    pub aria_expanded: bool,
60    /// 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.
61    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
62    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
63    pub aria_grabbed: bool,
64    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
65    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
66    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
67    pub aria_hidden: bool,
68    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
69    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
71    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
72    /// Defines a string value that labels the current element. See related aria-labelledby.
73    pub aria_label: std::option::Option<std::borrow::Cow<'static, str>>,
74    /// Identifies the element (or elements) that labels the current element. See related aria-label and aria-describedby.
75    pub aria_labelled_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
76    /// 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.
77    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
78    /// Indicates that the user can select more than one item from the current selectable descendants.
79    pub aria_multi_selectable: bool,
80    /// Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
81    pub aria_orientation: std::option::Option<std::borrow::Cow<'static, str>>,
82    /// 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.
83    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
84    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
85    pub aria_read_only: bool,
86    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
87    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
88    /// Indicates that user input is required on the element before a form can be submitted.
89    pub aria_required: bool,
90    /// Defines a human-readable, author-localized description for the role of an element.
91    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
92}
93impl crate::RenderElement for Select {
94    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
95        write!(writer, "<select")?;
96        if let Some(field) = self.autocomplete.as_ref() {
97            write!(writer, r#" autocomplete="{field}""#)?;
98        }
99        if self.disabled {
100            write!(writer, r#" disabled"#)?;
101        }
102        if let Some(field) = self.form.as_ref() {
103            write!(writer, r#" form="{field}""#)?;
104        }
105        if self.multiple {
106            write!(writer, r#" multiple"#)?;
107        }
108        if let Some(field) = self.name.as_ref() {
109            write!(writer, r#" name="{field}""#)?;
110        }
111        if self.required {
112            write!(writer, r#" required"#)?;
113        }
114        if let Some(field) = self.size.as_ref() {
115            write!(writer, r#" size="{field}""#)?;
116        }
117        if let Some(field) = self.role.as_ref() {
118            write!(writer, r#" role="{field}""#)?;
119        }
120        if let Some(field) = self.aria_active_descendant_element.as_ref() {
121            write!(writer, r#" aria-activedescendant="{field}""#)?;
122        }
123        if self.aria_atomic {
124            write!(writer, r#" aria-atomic"#)?;
125        }
126        if let Some(field) = self.aria_auto_complete.as_ref() {
127            write!(writer, r#" aria-autocomplete="{field}""#)?;
128        }
129        if let Some(field) = self.aria_braille_label.as_ref() {
130            write!(writer, r#" aria-braillelabel="{field}""#)?;
131        }
132        if let Some(field) = self.aria_braille_role_description.as_ref() {
133            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
134        }
135        if self.aria_busy {
136            write!(writer, r#" aria-busy"#)?;
137        }
138        if let Some(field) = self.aria_controls_elements.as_ref() {
139            write!(writer, r#" aria-controls="{field}""#)?;
140        }
141        if let Some(field) = self.aria_current.as_ref() {
142            write!(writer, r#" aria-current="{field}""#)?;
143        }
144        if let Some(field) = self.aria_described_by_elements.as_ref() {
145            write!(writer, r#" aria-describedby="{field}""#)?;
146        }
147        if let Some(field) = self.aria_description.as_ref() {
148            write!(writer, r#" aria-description="{field}""#)?;
149        }
150        if let Some(field) = self.aria_details_elements.as_ref() {
151            write!(writer, r#" aria-details="{field}""#)?;
152        }
153        if self.aria_disabled {
154            write!(writer, r#" aria-disabled"#)?;
155        }
156        if let Some(field) = self.aria_drop_effect.as_ref() {
157            write!(writer, r#" aria-dropeffect="{field}""#)?;
158        }
159        if let Some(field) = self.aria_error_message_elements.as_ref() {
160            write!(writer, r#" aria-errormessage="{field}""#)?;
161        }
162        if self.aria_expanded {
163            write!(writer, r#" aria-expanded"#)?;
164        }
165        if let Some(field) = self.aria_flow_to_elements.as_ref() {
166            write!(writer, r#" aria-flowto="{field}""#)?;
167        }
168        if self.aria_grabbed {
169            write!(writer, r#" aria-grabbed"#)?;
170        }
171        if let Some(field) = self.aria_has_popup.as_ref() {
172            write!(writer, r#" aria-haspopup="{field}""#)?;
173        }
174        if self.aria_hidden {
175            write!(writer, r#" aria-hidden"#)?;
176        }
177        if let Some(field) = self.aria_invalid.as_ref() {
178            write!(writer, r#" aria-invalid="{field}""#)?;
179        }
180        if let Some(field) = self.aria_key_shortcuts.as_ref() {
181            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
182        }
183        if let Some(field) = self.aria_label.as_ref() {
184            write!(writer, r#" aria-label="{field}""#)?;
185        }
186        if let Some(field) = self.aria_labelled_by_elements.as_ref() {
187            write!(writer, r#" aria-labelledby="{field}""#)?;
188        }
189        if let Some(field) = self.aria_live.as_ref() {
190            write!(writer, r#" aria-live="{field}""#)?;
191        }
192        if self.aria_multi_selectable {
193            write!(writer, r#" aria-multiselectable"#)?;
194        }
195        if let Some(field) = self.aria_orientation.as_ref() {
196            write!(writer, r#" aria-orientation="{field}""#)?;
197        }
198        if let Some(field) = self.aria_owns_elements.as_ref() {
199            write!(writer, r#" aria-owns="{field}""#)?;
200        }
201        if self.aria_read_only {
202            write!(writer, r#" aria-readonly"#)?;
203        }
204        if let Some(field) = self.aria_relevant.as_ref() {
205            write!(writer, r#" aria-relevant="{field}""#)?;
206        }
207        if self.aria_required {
208            write!(writer, r#" aria-required"#)?;
209        }
210        if let Some(field) = self.aria_role_description.as_ref() {
211            write!(writer, r#" aria-roledescription="{field}""#)?;
212        }
213        write!(writer, "{}", self.global_attrs)?;
214        write!(writer, "{}", self.data_map)?;
215        write!(writer, ">")?;
216        Ok(())
217    }
218    #[allow(unused_variables)]
219    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
220        write!(writer, "</select>")?;
221        Ok(())
222    }
223}
224impl std::fmt::Display for Select {
225    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
226        use crate::RenderElement;
227        self.write_opening_tag(writer)?;
228        self.write_closing_tag(writer)?;
229        Ok(())
230    }
231}
232impl std::ops::Deref for Select {
233    type Target = crate::GlobalAttributes;
234    fn deref(&self) -> &Self::Target {
235        &self.global_attrs
236    }
237}
238impl std::ops::DerefMut for Select {
239    fn deref_mut(&mut self) -> &mut Self::Target {
240        &mut self.global_attrs
241    }
242}