Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where dialog is unable to be closed #2288

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/eleven-steaks-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/view-components': patch
---

Fixes issue where sometimes a dialog cannot be closed if another is open

<!-- Changed components: Primer::Alpha::Dialog -->
21 changes: 9 additions & 12 deletions app/components/primer/alpha/modal_dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ function clickHandler(event: Event) {
return
}
}
// Find the top level dialog that is open.
const topLevelDialog = overlayStack[overlayStack.length - 1]
if (!topLevelDialog) return
Comment on lines -33 to -35
Copy link
Contributor Author

@TylerJDev TylerJDev Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did not seem like we needed to rely on checking if the "top level" dialog was open at this point. The function should only be ran the moment a user clicks the close button. This should only target the dialog where that event stemmed, and shouldn't affect any other dialogs that are open.

I removed this logic and replaced it with a conditional that will only check if one of the two acceptable button data-* attributes exist.


dialogId = button.getAttribute('data-close-dialog-id')
if (dialogId === topLevelDialog.id) {
overlayStack.pop()
topLevelDialog.close()
}
if (!overlayStack.length) return

dialogId = button.getAttribute('data-submit-dialog-id')
if (dialogId === topLevelDialog.id) {
overlayStack.pop()
topLevelDialog.close(true)
dialogId = button.getAttribute('data-close-dialog-id') || button.getAttribute('data-submit-dialog-id')
if (dialogId) {
const dialog = document.getElementById(dialogId)
if (dialog instanceof ModalDialogElement) {
const dialogIndex = overlayStack.findIndex(ele => ele.id === dialogId)
overlayStack.splice(dialogIndex, 1)
dialog.close(button.hasAttribute('data-submit-dialog-id'))
}
}
}

Expand Down
Loading