MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / AlertDialogContent

Function AlertDialogContent

primitives/src/alert_dialog.rs:175–218  ·  view source on GitHub ↗
(props: AlertDialogContentProps)

Source from the content-addressed store, hash-verified

173/// ```
174#[component]
175pub 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)]

Callers

nothing calls this directly

Calls 3

use_unique_idFunction · 0.85
use_id_orFunction · 0.85

Tested by

no test coverage detected