html_sys/interactive/
dialog.rs

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