Use of Dialog (controlled) without Dialog.Trigger? #1234
Replies: 9 comments 30 replies
-
Hey @janhoogeveen, generally you want to avoid showing dialogs without any user interactions, that's why the trigger exists as it is an integral part of the accessibility of the pattern (focus management, attributes, etc). I think that's generally a dark pattern UX-wise to open without user intent. Regardless, in your case, if you don't use it, what you describe sounds like it could be a bug potentially. Can you send me a quick sandbox reproducing it so I can take a look and see if it's actually a bug or just mis-use of the component? Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
-
Hey @benoitgrelard you mentioned that dialogs that render without a trigger feel like a dark pattern, but what about There are countless ways that I've been asked to display a modal without a trigger. I feel like the API of Dialog is really limiting on this front. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am having a similar issue. I need to show a confirm box if the user tries to navigate away from a page containing an unsaved form. cheers |
Beta Was this translation helpful? Give feedback.
-
Hi there! I`m having issue with Dialog and Trigger too. In my form I have control panel with saving options, and on click any of this option should open a dialog with progress bar. But it only should appear if form valid, and validation occur also on click this button. Could anyone show how to solve this issue? |
Beta Was this translation helpful? Give feedback.
-
Its simple, Dialog require trigger right, pass a button as a trigger and give button some id like |
Beta Was this translation helpful? Give feedback.
-
Another case in which having this api does not hold up is opening a modal from a popover menu. I.e. you have a button that opens a menu of which an item's click triggers opening a modal. You usually want the menu to hide upon an item click, but if we hide (unmount) that menu, the trigger disappears and so does the entire modal. The only way to solve this with the current api is probably using some hacks around keeping the modal rendered, but not visible, which is pretty dirty. |
Beta Was this translation helpful? Give feedback.
-
I have yet another situation; I'm hoping the solution's already out there: I have a modal window that opens by some normal button, etc. Somewhere on this modal is a button. In this case, similar to the Dropdown Item, there is a clear trigger that's inside a component that disappears once triggered. Only, in this case, it's in another modal. Following the same logic in #1836 for the Dropdown, one might think to put the second dialog's Trigger inside the first dialog's Content and then wrap the first dialog inside the second. But if I'm guessing correctly, sticking a trigger inside of a dialog's content will link to that dialog, not one that is wrapping it. Is that correct? e.g. <Dialog.Root> {/* second dialog */}
<Dialog.Root> {/* first dialog*/}
<Dialog.Trigger> {/* open first dialog */}
<button>Open first dialog</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<p>First dialog content</p>
<Dialog.Trigger> {/* This trigger links to the first dialog, not the second, doesn't it? */}
<Dialog.Close>
<button>Open second dialog</button>
</Dialog.Close>
</Dialog.Trigger>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<p>Second dialog content</p>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root> If this is the case, how could this situation be handled correctly? |
Beta Was this translation helpful? Give feedback.
-
I resorted to use different library such as https://headlessui.com/ for the dialog. |
Beta Was this translation helpful? Give feedback.
-
only one thing that comes in my mind is to make custom <DialogClose ref={closeDialogRef} className="hidden" />
closeDialogRef.current?.click(); |
Beta Was this translation helpful? Give feedback.
-
Hey everyone,
I'm trying to open a Dialog on route changes. The use case here is that I want a modal window on certain drilldown pages in Next.js using a catch-all route, and hide it when certain parameters are missing. I thought making a controlled Dialog would be a good solution here.
The way I open the Dialog is as follows:
/main/:mainId
/main/:mainId/sub/:subId
though anext/link
useEffect
hook listening to:subId
, I set the Dialog to open.For the most part this is working as expected. There is one issue though. Once I close the Dialog, on touch devices things like sliders don't work anymore. They don't respond to any swipe events until you tap on a non interactive part of the page. I suspect it's because Dialog tries to reset focus to the previous focus state and it can't find the Trigger. Or any trigger for that matter.
The docs say this about it.
Escape key
I'm not using a Dialog.Trigger. Could this be the cause for this behaviour? It's not entirely clear for me if a Dialog implementation needs to use all parts listed in the documentation.
Update 1
Looks like the body has
pointer-events: none
set to it, which disappears as soon as I click or tap somewhere in the body.Update 2
This is probably an issue due to the bodyPointerLock util, not because of the absence of a Trigger
Beta Was this translation helpful? Give feedback.
All reactions