Skip to content

Commit f812a98

Browse files
authored
Merge pull request #254 from opf/fix/form-in-dialog
Dialogs close when moving mouse outside of it
2 parents 4cad42b + 32d294a commit f812a98

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Diff for: .changeset/no-close-dialog-with-form.md

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

Diff for: app/components/primer/dialog_helper.ts

+3
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 &&

Diff for: test/system/alpha/dialog_test.rb

+9
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)