Skip to content

Commit b2c0078

Browse files
klaustopherHDinger
authored andcommitted
Do not close dialog when clicking on the backdrop when it contains a form (primer#3334)
1 parent 4cad42b commit b2c0078

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
Do not close dialogs when clicking on the backdrop if the dialog contains a form

app/components/primer/dialog_helper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export class DialogHelperElement extends HTMLElement {
111111
// The click target _must_ be the dialog element itself, and not elements underneath or inside.
112112
if (target !== dialog || !dialog?.open) return
113113

114+
// If the dialog contains a form, do not close the dialog when clicking outside of the dialog
115+
if (dialog.querySelector('form')) return
116+
114117
const rect = dialog.getBoundingClientRect()
115118
const clickWasInsideDialog =
116119
rect.top <= event.clientY &&

test/system/alpha/dialog_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def test_outside_click_closes_dialog
8989
refute_selector "dialog[open]"
9090
end
9191

92+
def test_outside_click_does_not_close_dialog_with_form
93+
visit_preview(:with_form)
94+
95+
click_button("Show Dialog")
96+
mouse.click(x: 0, y: 0)
97+
98+
assert_selector "dialog[open]"
99+
end
100+
92101
def test_outside_menu_click_does_not_close_dialog
93102
visit_preview(:with_auto_complete)
94103

0 commit comments

Comments
 (0)