Skip to main content

lumen_dioxus/overlays/
dialog.rs

1//! Dialogs: `Dialog` and its parts, `AlertDialog`, `Sheet`, `Drawer`, `DialogTrigger`, and
2//! [`use_dialog`].
3//!
4//! lumen-react opens these with `showModal()`. Dioxus Native has no top layer, so lumen-dioxus
5//! renders `<dialog open>` in the tree with a modal [`DismissLayer`] behind it. Escape closes the
6//! dialog through a key handler on the dialog, focus moves to the dialog when it opens, and a
7//! [`DialogTrigger`] gets focus back when it closes. While a
8//! [`DialogForm`](super::DialogForm) submission is pending, the dialog is marked
9//! `data-dismiss-locked` and Escape, outside clicks, and [`DialogClose`] leave it open.
10
11use std::rc::Rc;
12
13use dioxus::prelude::*;
14
15use super::dialog_form::DialogFormContext;
16use super::shared::{button_class, focus_stored, surface};
17use crate::class::{Glass, compose};
18use crate::hooks::{Controllable, use_controllable};
19use crate::overlay::{DismissLayer, is_escape};
20use crate::{ButtonSize, ButtonVariant};
21
22/// Open state and trigger of a dialog, shared by a [`DialogTrigger`] and the dialog it opens.
23///
24/// Create it with [`use_dialog`]. It is `Copy`, so event handlers can capture it.
25#[derive(Clone, Copy, PartialEq)]
26pub struct DialogController {
27    open: Signal<bool>,
28    trigger: Signal<Option<Rc<MountedData>>>,
29}
30
31impl DialogController {
32    /// Whether the dialog is open. Reading it subscribes the component.
33    pub fn is_open(&self) -> bool {
34        *self.open.read()
35    }
36
37    /// Opens or closes the dialog.
38    pub fn set_open(&self, open: bool) {
39        let mut state = self.open;
40
41        if *state.peek() != open {
42            state.set(open);
43        }
44    }
45
46    /// Opens the dialog.
47    pub fn open(&self) {
48        self.set_open(true);
49    }
50
51    /// Closes the dialog. Focus returns to the [`DialogTrigger`].
52    pub fn close(&self) {
53        self.set_open(false);
54    }
55
56    /// Opens a closed dialog or closes an open one.
57    pub fn toggle(&self) {
58        let open = *self.open.peek();
59        self.set_open(!open);
60    }
61
62    /// Whether the dialog is open, without subscribing the component.
63    pub(super) fn is_open_untracked(&self) -> bool {
64        *self.open.peek()
65    }
66
67    /// Sets the element that gets focus back when the dialog closes; `None` restores nothing.
68    pub(super) fn set_trigger(&self, node: Option<Rc<MountedData>>) {
69        let mut trigger = self.trigger;
70        trigger.set(node);
71    }
72}
73
74/// A closed dialog controller, like `useDialog` in lumen-react. Pass it to a [`DialogTrigger`]
75/// and to the `dialog` prop of [`Dialog`], [`AlertDialog`], [`Sheet`], or [`Drawer`].
76pub fn use_dialog() -> DialogController {
77    use_hook(|| DialogController {
78        open: Signal::new(false),
79        trigger: Signal::new(None),
80    })
81}
82
83/// Props for [`DialogTrigger`].
84#[derive(Props, Clone, PartialEq)]
85pub struct DialogTriggerProps {
86    /// The dialog this button opens.
87    pub dialog: DialogController,
88    /// Visual treatment.
89    #[props(default)]
90    pub variant: ButtonVariant,
91    /// Control size.
92    #[props(default)]
93    pub size: ButtonSize,
94    /// Disables the trigger.
95    #[props(default)]
96    pub disabled: bool,
97    /// Click handler. Call `prevent_default()` to keep the dialog closed.
98    pub onclick: Option<EventHandler<MouseEvent>>,
99    /// Extra classes appended after the Lumen classes.
100    #[props(into)]
101    pub class: Option<String>,
102    /// Any other `<button>` or global attribute.
103    #[props(extends = GlobalAttributes, extends = button)]
104    pub attributes: Vec<Attribute>,
105    /// Button label.
106    pub children: Element,
107}
108
109/// A Lumen button that opens a dialog and gets focus back when the dialog closes.
110#[component]
111pub fn DialogTrigger(props: DialogTriggerProps) -> Element {
112    let dialog = props.dialog;
113    let onclick = props.onclick;
114    let mut trigger = dialog.trigger;
115    let class = button_class(props.variant, props.size, props.class.as_deref());
116
117    rsx! {
118        button {
119            aria_haspopup: "dialog",
120            class,
121            "data-slot": "button",
122            disabled: props.disabled,
123            r#type: "button",
124            onclick: move |event: MouseEvent| {
125                if let Some(handler) = onclick {
126                    handler.call(event.clone());
127                }
128
129                if event.default_action_enabled() {
130                    dialog.open();
131                }
132            },
133            onmounted: move |event| trigger.set(Some(event.data())),
134            ..props.attributes,
135            span { class: "ui-button__content", {props.children} }
136        }
137    }
138}
139
140/// Open state shared by a dialog shell, its [`DialogClose`] buttons, and a
141/// [`DialogForm`](super::DialogForm) inside it.
142#[derive(Clone, Copy)]
143pub(super) struct DialogHandle {
144    state: Controllable<bool>,
145    controller: CopyValue<Option<DialogController>>,
146    /// Set while a `DialogForm` submission is pending, like lumen-core's `data-dismiss-locked`.
147    locked: Signal<bool>,
148}
149
150impl DialogHandle {
151    pub(super) fn set_open(self, open: bool) {
152        if let Some(controller) = *self.controller.peek() {
153            controller.set_open(open);
154        }
155
156        self.state.set(open);
157    }
158
159    /// Whether the dialog is open. Reading it subscribes the component.
160    pub(super) fn is_open(self) -> bool {
161        self.state.get()
162    }
163
164    /// Closes the dialog for Escape, an outside click, or a [`DialogClose`], unless a pending
165    /// `DialogForm` locked dismissal.
166    fn dismiss(self) {
167        if !*self.locked.peek() {
168            self.set_open(false);
169        }
170    }
171
172    /// Locks or releases dismissal.
173    pub(super) fn set_locked(self, locked: bool) {
174        let mut state = self.locked;
175
176        if *state.peek() != locked {
177            state.set(locked);
178        }
179    }
180
181    /// Releases the lock while a `DialogForm` unmounts, when the dialog may be tearing down too.
182    pub(super) fn release_lock(self) {
183        let mut state = self.locked;
184
185        if let Ok(mut locked) = state.try_write() {
186            *locked = false;
187        }
188    }
189}
190
191pub(super) fn use_dialog_handle(
192    controller: Option<DialogController>,
193    open: Option<bool>,
194    default_open: bool,
195    on_open_change: Option<EventHandler<bool>>,
196) -> DialogHandle {
197    let open_value = controller.map(|owner| owner.is_open()).or(open);
198    let state = use_controllable(open_value, || default_open, on_open_change);
199    let mut stored = use_hook(|| CopyValue::new(controller));
200    stored.set(controller);
201    let locked = use_signal(|| false);
202    let handle = DialogHandle {
203        state,
204        controller: stored,
205        locked,
206    };
207
208    use_context_provider(|| handle);
209    handle
210}
211
212#[derive(Clone, Copy, PartialEq, Eq)]
213pub(super) enum DialogKind {
214    Dialog,
215    Sheet,
216    Drawer,
217}
218
219pub(super) struct DialogShell {
220    pub(super) handle: DialogHandle,
221    pub(super) kind: DialogKind,
222    pub(super) alert: bool,
223    pub(super) class: String,
224    pub(super) layout: Option<&'static str>,
225    pub(super) surface: &'static str,
226    pub(super) dismiss_on_escape: bool,
227    pub(super) dismiss_on_outside_press: bool,
228    /// Element focused when the dialog opens, such as a search field. Defaults to the dialog.
229    pub(super) initial_focus: Option<Signal<Option<Rc<MountedData>>>>,
230    pub(super) attributes: Vec<Attribute>,
231    pub(super) children: Element,
232}
233
234/// Focus moves into the dialog (or `initial_focus`, once mounted) when it opens and back to the
235/// controller's trigger when it closes.
236fn use_dialog_focus(
237    open: bool,
238    handle: DialogHandle,
239    node: Signal<Option<Rc<MountedData>>>,
240    initial_focus: Option<Signal<Option<Rc<MountedData>>>>,
241) {
242    let mut was_open = use_hook(|| CopyValue::new(false));
243
244    use_effect(use_reactive((&open,), move |(open,)| {
245        let previous = *was_open.peek();
246        was_open.set(open);
247
248        if open && !previous {
249            let initial = initial_focus.and_then(|target| target.peek().clone());
250            focus_stored(initial.or_else(|| node.peek().clone()));
251        } else if !open
252            && previous
253            && let Some(controller) = *handle.controller.peek()
254        {
255            focus_stored(controller.trigger.peek().clone());
256        }
257    }));
258}
259
260pub(super) fn render_dialog(shell: DialogShell) -> Element {
261    let DialogShell {
262        handle,
263        kind,
264        alert,
265        class,
266        layout,
267        surface,
268        dismiss_on_escape,
269        dismiss_on_outside_press,
270        initial_focus,
271        attributes,
272        children,
273    } = shell;
274    let open = handle.state.get();
275    let locked = *handle.locked.read();
276    let mut node = use_signal(|| None::<Rc<MountedData>>);
277    use_dialog_focus(open, handle, node, initial_focus);
278    // Sheets and drawers have no z-index of their own; lift them above the dismiss layer.
279    let lifted = open && kind != DialogKind::Dialog;
280
281    rsx! {
282        if open {
283            DismissLayer {
284                modal: true,
285                on_dismiss: move |()| {
286                    if dismiss_on_outside_press {
287                        handle.dismiss();
288                    }
289                },
290            }
291        }
292        dialog {
293            aria_modal: "true",
294            class,
295            "data-dismiss-locked": locked.then_some(""),
296            "data-layout": layout,
297            "data-surface": surface,
298            "data-ui-alert-dialog": alert.then_some("true"),
299            "data-ui-bound": "true",
300            "data-ui-dialog": (!alert).then_some("true"),
301            "data-ui-drawer": (kind == DialogKind::Drawer).then_some("true"),
302            "data-ui-sheet": (kind == DialogKind::Sheet).then_some("true"),
303            open,
304            role: if alert { "alertdialog" } else { "dialog" },
305            style: lifted.then_some("z-index: 50"),
306            tabindex: open.then_some("-1"),
307            onkeydown: move |event: KeyboardEvent| {
308                if !is_escape(&event) || !event.default_action_enabled() {
309                    return;
310                }
311
312                event.prevent_default();
313                event.stop_propagation();
314
315                if dismiss_on_escape {
316                    handle.dismiss();
317                }
318            },
319            onmounted: move |event| node.set(Some(event.data())),
320            ..attributes,
321            {children}
322        }
323    }
324}
325
326/// Layout of a [`Dialog`].
327#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
328#[non_exhaustive]
329pub enum DialogLayout {
330    /// A centered panel.
331    #[default]
332    Centered,
333    /// Covers the whole viewport.
334    Fullscreen,
335    /// Centered on wide screens, a bottom sheet on narrow ones.
336    Responsive,
337}
338
339impl DialogLayout {
340    /// The `data-layout` value.
341    pub fn as_str(self) -> &'static str {
342        match self {
343            Self::Centered => "centered",
344            Self::Fullscreen => "fullscreen",
345            Self::Responsive => "responsive",
346        }
347    }
348}
349
350/// Props for [`Dialog`].
351#[derive(Props, Clone, PartialEq)]
352pub struct DialogProps {
353    /// A controller from [`use_dialog`]. It owns the open state and lets a [`DialogTrigger`] get
354    /// focus back when the dialog closes.
355    pub dialog: Option<DialogController>,
356    /// Controlled open state.
357    pub open: Option<bool>,
358    /// Initial open state when uncontrolled.
359    #[props(default)]
360    pub default_open: bool,
361    /// Called with the requested open state.
362    pub on_open_change: Option<EventHandler<bool>>,
363    /// Makes it an `alertdialog` that ignores outside clicks by default.
364    #[props(default)]
365    pub alert: bool,
366    /// Closes on Escape. Defaults to true.
367    #[props(default = true)]
368    pub dismiss_on_escape: bool,
369    /// Closes on a click outside the dialog. Defaults to true, or false for alerts.
370    pub dismiss_on_outside_press: Option<bool>,
371    /// Layout.
372    #[props(default)]
373    pub layout: DialogLayout,
374    /// Glass intensity.
375    #[props(default, into)]
376    pub glass: Glass,
377    /// Extra classes appended after the Lumen classes.
378    #[props(into)]
379    pub class: Option<String>,
380    /// Any other `<dialog>` or global attribute. Name the dialog with `aria_labelledby`.
381    #[props(extends = GlobalAttributes, extends = dialog)]
382    pub attributes: Vec<Attribute>,
383    /// [`DialogHeader`], [`DialogBody`], [`DialogFooter`], or any content.
384    pub children: Element,
385}
386
387/// A modal dialog with Lumen's dialog surface.
388#[component]
389pub fn Dialog(props: DialogProps) -> Element {
390    let handle = use_dialog_handle(
391        props.dialog,
392        props.open,
393        props.default_open,
394        props.on_open_change,
395    );
396    let glass = props.glass.class("ui-dialog");
397    let class = compose([
398        Some("ui-dialog"),
399        props.alert.then_some("ui-alert-dialog"),
400        (props.layout == DialogLayout::Fullscreen).then_some("ui-dialog--fullscreen"),
401        (props.layout == DialogLayout::Responsive).then_some("ui-dialog--responsive"),
402        glass.as_deref(),
403        props.class.as_deref(),
404    ]);
405
406    render_dialog(DialogShell {
407        handle,
408        kind: DialogKind::Dialog,
409        alert: props.alert,
410        class,
411        layout: Some(props.layout.as_str()),
412        surface: surface(props.glass),
413        dismiss_on_escape: props.dismiss_on_escape,
414        dismiss_on_outside_press: props.dismiss_on_outside_press.unwrap_or(!props.alert),
415        initial_focus: None,
416        attributes: props.attributes,
417        children: props.children,
418    })
419}
420
421/// Props shared by [`AlertDialog`] and [`Drawer`].
422#[derive(Props, Clone, PartialEq)]
423pub struct DialogSurfaceProps {
424    /// A controller from [`use_dialog`]. It owns the open state and lets a [`DialogTrigger`] get
425    /// focus back when the dialog closes.
426    pub dialog: Option<DialogController>,
427    /// Controlled open state.
428    pub open: Option<bool>,
429    /// Initial open state when uncontrolled.
430    #[props(default)]
431    pub default_open: bool,
432    /// Called with the requested open state.
433    pub on_open_change: Option<EventHandler<bool>>,
434    /// Closes on Escape. Defaults to true.
435    #[props(default = true)]
436    pub dismiss_on_escape: bool,
437    /// Closes on a click outside. Defaults to true, or false for [`AlertDialog`].
438    pub dismiss_on_outside_press: Option<bool>,
439    /// Glass intensity.
440    #[props(default, into)]
441    pub glass: Glass,
442    /// Extra classes appended after the Lumen classes.
443    #[props(into)]
444    pub class: Option<String>,
445    /// Any other `<dialog>` or global attribute. Name the dialog with `aria_labelledby`.
446    #[props(extends = GlobalAttributes, extends = dialog)]
447    pub attributes: Vec<Attribute>,
448    /// Dialog content.
449    pub children: Element,
450}
451
452/// Props for [`AlertDialog`].
453pub type AlertDialogProps = DialogSurfaceProps;
454/// Props for [`Drawer`].
455pub type DrawerProps = DialogSurfaceProps;
456
457/// The inline edge a [`Sheet`] docks to and slides in from.
458#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
459#[non_exhaustive]
460pub enum SheetSide {
461    /// The inline start: the left, or the right on right-to-left pages. Suits filters.
462    Start,
463    /// The inline end: the right, or the left on right-to-left pages.
464    #[default]
465    End,
466}
467
468impl SheetSide {
469    /// The side name, like lumen-react's `side` prop.
470    pub fn as_str(self) -> &'static str {
471        match self {
472            Self::Start => "start",
473            Self::End => "end",
474        }
475    }
476}
477
478/// Props for [`Sheet`].
479#[derive(Props, Clone, PartialEq)]
480pub struct SheetProps {
481    /// A controller from [`use_dialog`]. It owns the open state and lets a [`DialogTrigger`] get
482    /// focus back when the sheet closes.
483    pub dialog: Option<DialogController>,
484    /// Controlled open state.
485    pub open: Option<bool>,
486    /// Initial open state when uncontrolled.
487    #[props(default)]
488    pub default_open: bool,
489    /// Called with the requested open state.
490    pub on_open_change: Option<EventHandler<bool>>,
491    /// Closes on Escape. Defaults to true.
492    #[props(default = true)]
493    pub dismiss_on_escape: bool,
494    /// Closes on a click outside. Defaults to true.
495    pub dismiss_on_outside_press: Option<bool>,
496    /// The inline edge the sheet docks to and slides in from. Defaults to the end.
497    #[props(default)]
498    pub side: SheetSide,
499    /// Glass intensity.
500    #[props(default, into)]
501    pub glass: Glass,
502    /// Extra classes appended after the Lumen classes.
503    #[props(into)]
504    pub class: Option<String>,
505    /// Any other `<dialog>` or global attribute. Name the sheet with `aria_labelledby`.
506    #[props(extends = GlobalAttributes, extends = dialog)]
507    pub attributes: Vec<Attribute>,
508    /// Sheet content.
509    pub children: Element,
510}
511
512/// A confirmation dialog with the `alertdialog` role. Outside clicks do not close it.
513#[component]
514pub fn AlertDialog(props: DialogSurfaceProps) -> Element {
515    let handle = use_dialog_handle(
516        props.dialog,
517        props.open,
518        props.default_open,
519        props.on_open_change,
520    );
521    let glass = props.glass.class("ui-dialog");
522    let class = compose([
523        Some("ui-dialog ui-alert-dialog"),
524        glass.as_deref(),
525        props.class.as_deref(),
526    ]);
527
528    render_dialog(DialogShell {
529        handle,
530        kind: DialogKind::Dialog,
531        alert: true,
532        class,
533        layout: None,
534        surface: surface(props.glass),
535        dismiss_on_escape: props.dismiss_on_escape,
536        dismiss_on_outside_press: props.dismiss_on_outside_press.unwrap_or(false),
537        initial_focus: None,
538        attributes: props.attributes,
539        children: props.children,
540    })
541}
542
543fn side_panel(
544    props: DialogSurfaceProps,
545    kind: DialogKind,
546    base: &str,
547    modifier: Option<&str>,
548) -> Element {
549    let handle = use_dialog_handle(
550        props.dialog,
551        props.open,
552        props.default_open,
553        props.on_open_change,
554    );
555    let glass = props.glass.class(base);
556    let class = compose([
557        Some(base),
558        modifier,
559        glass.as_deref(),
560        props.class.as_deref(),
561    ]);
562
563    render_dialog(DialogShell {
564        handle,
565        kind,
566        alert: false,
567        class,
568        layout: None,
569        surface: surface(props.glass),
570        dismiss_on_escape: props.dismiss_on_escape,
571        dismiss_on_outside_press: props.dismiss_on_outside_press.unwrap_or(true),
572        initial_focus: None,
573        attributes: props.attributes,
574        children: props.children,
575    })
576}
577
578/// A modal panel that slides in from an inline edge: the end by default, for details and
579/// settings, or the start with [`SheetSide::Start`], for start-edge panels such as filters.
580#[component]
581pub fn Sheet(props: SheetProps) -> Element {
582    let SheetProps {
583        dialog,
584        open,
585        default_open,
586        on_open_change,
587        dismiss_on_escape,
588        dismiss_on_outside_press,
589        side,
590        glass,
591        class,
592        attributes,
593        children,
594    } = props;
595
596    side_panel(
597        DialogSurfaceProps {
598            dialog,
599            open,
600            default_open,
601            on_open_change,
602            dismiss_on_escape,
603            dismiss_on_outside_press,
604            glass,
605            class,
606            attributes,
607            children,
608        },
609        DialogKind::Sheet,
610        "ui-sheet",
611        (side == SheetSide::Start).then_some("ui-sheet--start"),
612    )
613}
614
615/// A modal panel that slides up from the bottom, for filters and quick actions.
616#[component]
617pub fn Drawer(props: DialogSurfaceProps) -> Element {
618    side_panel(props, DialogKind::Drawer, "ui-drawer", None)
619}
620
621/// Props shared by [`DialogHeader`], [`DialogBody`], and [`DialogFooter`].
622#[derive(Props, Clone, PartialEq)]
623pub struct DialogPartProps {
624    /// Extra classes appended after the Lumen class.
625    #[props(into)]
626    pub class: Option<String>,
627    /// Any other global attribute.
628    #[props(extends = GlobalAttributes)]
629    pub attributes: Vec<Attribute>,
630    /// Content.
631    pub children: Element,
632}
633
634/// The `<header>` of a dialog, usually a [`DialogTitle`] and a description.
635#[component]
636pub fn DialogHeader(props: DialogPartProps) -> Element {
637    let class = compose([Some("ui-dialog-header"), props.class.as_deref()]);
638
639    rsx! {
640        header { class, "data-slot": "dialog-header", ..props.attributes, {props.children} }
641    }
642}
643
644/// The main content of a dialog.
645#[component]
646pub fn DialogBody(props: DialogPartProps) -> Element {
647    let class = compose([Some("ui-dialog-body"), props.class.as_deref()]);
648
649    rsx! {
650        div { class, "data-slot": "dialog-body", ..props.attributes, {props.children} }
651    }
652}
653
654/// The `<footer>` of a dialog, usually actions.
655#[component]
656pub fn DialogFooter(props: DialogPartProps) -> Element {
657    let class = compose([Some("ui-dialog-footer"), props.class.as_deref()]);
658
659    rsx! {
660        footer { class, "data-slot": "dialog-footer", ..props.attributes, {props.children} }
661    }
662}
663
664/// Heading level of a [`DialogTitle`].
665#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
666#[non_exhaustive]
667pub enum DialogTitleLevel {
668    /// `<h2>`.
669    #[default]
670    H2,
671    /// `<h3>`.
672    H3,
673    /// `<h4>`.
674    H4,
675}
676
677/// Props for [`DialogTitle`].
678#[derive(Props, Clone, PartialEq)]
679pub struct DialogTitleProps {
680    /// Heading level, like `as` in lumen-react.
681    #[props(default)]
682    pub level: DialogTitleLevel,
683    /// Extra classes appended after the Lumen class.
684    #[props(into)]
685    pub class: Option<String>,
686    /// Any other global attribute. Give it an `id` and point the dialog's `aria_labelledby` at it.
687    #[props(extends = GlobalAttributes)]
688    pub attributes: Vec<Attribute>,
689    /// Title text.
690    pub children: Element,
691}
692
693/// The title of a dialog.
694#[component]
695pub fn DialogTitle(props: DialogTitleProps) -> Element {
696    let class = compose([Some("ui-dialog-title"), props.class.as_deref()]);
697
698    match props.level {
699        DialogTitleLevel::H2 => rsx! {
700            h2 { class, "data-slot": "dialog-title", ..props.attributes, {props.children} }
701        },
702        DialogTitleLevel::H3 => rsx! {
703            h3 { class, "data-slot": "dialog-title", ..props.attributes, {props.children} }
704        },
705        DialogTitleLevel::H4 => rsx! {
706            h4 { class, "data-slot": "dialog-title", ..props.attributes, {props.children} }
707        },
708    }
709}
710
711/// Props for [`DialogClose`].
712#[derive(Props, Clone, PartialEq)]
713pub struct DialogCloseProps {
714    /// Visual treatment.
715    #[props(default)]
716    pub variant: ButtonVariant,
717    /// Control size.
718    #[props(default)]
719    pub size: ButtonSize,
720    /// Disables the button.
721    #[props(default)]
722    pub disabled: bool,
723    /// Click handler. Call `prevent_default()` to keep the dialog open.
724    pub onclick: Option<EventHandler<MouseEvent>>,
725    /// Extra classes appended after the Lumen classes.
726    #[props(into)]
727    pub class: Option<String>,
728    /// Any other `<button>` or global attribute.
729    #[props(extends = GlobalAttributes, extends = button)]
730    pub attributes: Vec<Attribute>,
731    /// Button label.
732    pub children: Element,
733}
734
735/// A Lumen button that closes the dialog it is in. Inside a pending
736/// [`DialogForm`](super::DialogForm) it is disabled, and a locked dialog stays open.
737#[component]
738pub fn DialogClose(props: DialogCloseProps) -> Element {
739    let handle = try_use_context::<DialogHandle>();
740    let pending = try_use_context::<DialogFormContext>().is_some_and(DialogFormContext::is_pending);
741    let onclick = props.onclick;
742    let extra = compose([Some("ui-dialog-close"), props.class.as_deref()]);
743    let class = button_class(props.variant, props.size, Some(&extra));
744
745    rsx! {
746        button {
747            class,
748            "data-slot": "dialog-close",
749            disabled: props.disabled || pending,
750            r#type: "button",
751            onclick: move |event: MouseEvent| {
752                if let Some(handler) = onclick {
753                    handler.call(event.clone());
754                }
755
756                if event.default_action_enabled()
757                    && let Some(handle) = handle
758                {
759                    handle.dismiss();
760                }
761            },
762            ..props.attributes,
763            span { class: "ui-button__content", {props.children} }
764        }
765    }
766}