Skip to content

Commit e6d2551

Browse files
committed
fix(emcn): don't close modal when dismissing a dropdown via outside click
Radix dispatches pointer-down-outside to every open dismissable layer at once, so clicking outside an open dropdown/select inside a modal closed both the dropdown and the modal in one jarring step. ModalContent now prevents its own dismissal while a portaled popper layer is open — the first outside click closes just the popper, the next one closes the modal.
1 parent 8e37545 commit e6d2551

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • apps/sim/components/emcn/components/modal

apps/sim/components/emcn/components/modal/modal.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ const ModalContent = React.forwardRef<
217217
onPointerUp={(e) => {
218218
e.stopPropagation()
219219
}}
220+
onPointerDownOutside={(e) => {
221+
if (!isInteractionReady) {
222+
e.preventDefault()
223+
return
224+
}
225+
/**
226+
* Radix dispatches pointer-down-outside to every open layer at
227+
* once, so a click that should only dismiss an open dropdown /
228+
* select / combobox (portaled into a popper wrapper above this
229+
* modal) would also close the modal. Keep the modal open and let
230+
* the click dismiss just the popper layer.
231+
*/
232+
if (document.querySelector('[data-radix-popper-content-wrapper]')) {
233+
e.preventDefault()
234+
}
235+
}}
220236
onOpenAutoFocus={onOpenAutoFocus ?? focusFirstTextInput}
221237
aria-describedby={ariaDescribedBy}
222238
{...props}

0 commit comments

Comments
 (0)