html_sys/forms/
label.rs

1/// The HTML `<label>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label)
4#[doc(alias = "label")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Label {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Associate the label with form control
11    pub for_: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// 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.
13    pub aria_atomic: bool,
14    /// 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.
15    pub aria_braille_role_description: std::option::Option<
16        std::borrow::Cow<'static, str>,
17    >,
18    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
19    pub aria_busy: bool,
20    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
21    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
22    /// Indicates the element that represents the current item within a container or set of related elements.
23    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
24    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
25    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
27    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
29    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
30    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
31    pub aria_disabled: bool,
32    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
33    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
35    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// 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.
37    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
38    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
39    pub aria_grabbed: bool,
40    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
41    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
42    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
43    pub aria_hidden: bool,
44    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
45    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
47    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
48    /// 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.
49    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
50    /// 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.
51    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
52    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
53    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
54    /// Defines a human-readable, author-localized description for the role of an element.
55    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
56}
57impl crate::RenderElement for Label {
58    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
59        write!(writer, "<label")?;
60        if let Some(field) = self.for_.as_ref() {
61            write!(writer, r#" for="{field}""#)?;
62        }
63        if self.aria_atomic {
64            write!(writer, r#" aria-atomic"#)?;
65        }
66        if let Some(field) = self.aria_braille_role_description.as_ref() {
67            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
68        }
69        if self.aria_busy {
70            write!(writer, r#" aria-busy"#)?;
71        }
72        if let Some(field) = self.aria_controls_elements.as_ref() {
73            write!(writer, r#" aria-controls="{field}""#)?;
74        }
75        if let Some(field) = self.aria_current.as_ref() {
76            write!(writer, r#" aria-current="{field}""#)?;
77        }
78        if let Some(field) = self.aria_described_by_elements.as_ref() {
79            write!(writer, r#" aria-describedby="{field}""#)?;
80        }
81        if let Some(field) = self.aria_description.as_ref() {
82            write!(writer, r#" aria-description="{field}""#)?;
83        }
84        if let Some(field) = self.aria_details_elements.as_ref() {
85            write!(writer, r#" aria-details="{field}""#)?;
86        }
87        if self.aria_disabled {
88            write!(writer, r#" aria-disabled"#)?;
89        }
90        if let Some(field) = self.aria_drop_effect.as_ref() {
91            write!(writer, r#" aria-dropeffect="{field}""#)?;
92        }
93        if let Some(field) = self.aria_error_message_elements.as_ref() {
94            write!(writer, r#" aria-errormessage="{field}""#)?;
95        }
96        if let Some(field) = self.aria_flow_to_elements.as_ref() {
97            write!(writer, r#" aria-flowto="{field}""#)?;
98        }
99        if self.aria_grabbed {
100            write!(writer, r#" aria-grabbed"#)?;
101        }
102        if let Some(field) = self.aria_has_popup.as_ref() {
103            write!(writer, r#" aria-haspopup="{field}""#)?;
104        }
105        if self.aria_hidden {
106            write!(writer, r#" aria-hidden"#)?;
107        }
108        if let Some(field) = self.aria_invalid.as_ref() {
109            write!(writer, r#" aria-invalid="{field}""#)?;
110        }
111        if let Some(field) = self.aria_key_shortcuts.as_ref() {
112            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
113        }
114        if let Some(field) = self.aria_live.as_ref() {
115            write!(writer, r#" aria-live="{field}""#)?;
116        }
117        if let Some(field) = self.aria_owns_elements.as_ref() {
118            write!(writer, r#" aria-owns="{field}""#)?;
119        }
120        if let Some(field) = self.aria_relevant.as_ref() {
121            write!(writer, r#" aria-relevant="{field}""#)?;
122        }
123        if let Some(field) = self.aria_role_description.as_ref() {
124            write!(writer, r#" aria-roledescription="{field}""#)?;
125        }
126        write!(writer, "{}", self.global_attrs)?;
127        write!(writer, "{}", self.data_map)?;
128        write!(writer, ">")?;
129        Ok(())
130    }
131    #[allow(unused_variables)]
132    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
133        write!(writer, "</label>")?;
134        Ok(())
135    }
136}
137impl std::fmt::Display for Label {
138    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139        use crate::RenderElement;
140        self.write_opening_tag(writer)?;
141        self.write_closing_tag(writer)?;
142        Ok(())
143    }
144}
145impl std::ops::Deref for Label {
146    type Target = crate::GlobalAttributes;
147    fn deref(&self) -> &Self::Target {
148        &self.global_attrs
149    }
150}
151impl std::ops::DerefMut for Label {
152    fn deref_mut(&mut self) -> &mut Self::Target {
153        &mut self.global_attrs
154    }
155}