(props: AlertDialogContentProps)
| 173 | /// ``` |
| 174 | #[component] |
| 175 | pub fn AlertDialogContent(props: AlertDialogContentProps) -> Element { |
| 176 | let ctx: AlertDialogCtx = use_context(); |
| 177 | |
| 178 | let open = ctx.open; |
| 179 | let set_open = ctx.set_open; |
| 180 | |
| 181 | // Add a escape key listener to the document when the dialog is open. We can't |
| 182 | // just add this to the dialog itself because it might not be focused if the user |
| 183 | // is highlighting text or interacting with another element. |
| 184 | use_global_escape_listener(move || set_open.call(false)); |
| 185 | |
| 186 | let gen_id = use_unique_id(); |
| 187 | let id = use_id_or(gen_id, props.id); |
| 188 | use_effect(move || { |
| 189 | let eval = document::eval( |
| 190 | r#"let id = await dioxus.recv(); |
| 191 | let is_open = await dioxus.recv(); |
| 192 | let dialog = document.getElementById(id); |
| 193 | |
| 194 | if (is_open) { |
| 195 | dialog.trap = window.createFocusTrap(dialog); |
| 196 | } |
| 197 | if (!is_open && dialog.trap) { |
| 198 | dialog.trap.remove(); |
| 199 | dialog.trap = null; |
| 200 | }"#, |
| 201 | ); |
| 202 | let _ = eval.send(id.to_string()); |
| 203 | let _ = eval.send(open.cloned()); |
| 204 | }); |
| 205 | |
| 206 | rsx! { |
| 207 | div { |
| 208 | id, |
| 209 | role: "alertdialog", |
| 210 | aria_modal: "true", |
| 211 | aria_labelledby: ctx.labelledby.clone(), |
| 212 | aria_describedby: ctx.describedby.clone(), |
| 213 | class: props.class.clone().unwrap_or_else(|| "dx-alert-dialog".to_string()), |
| 214 | ..props.attributes, |
| 215 | {props.children} |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /// The props for the [`AlertDialogTitle`] component. |
| 221 | #[derive(Props, Clone, PartialEq)] |
nothing calls this directly
no test coverage detected