Skip to content

fix: prevent modal closing on inner clicks#685

Merged
danielroe merged 6 commits intonpmx-dev:mainfrom
cnaples79:fix/modal-click-close
Feb 2, 2026
Merged

fix: prevent modal closing on inner clicks#685
danielroe merged 6 commits intonpmx-dev:mainfrom
cnaples79:fix/modal-click-close

Conversation

@cnaples79
Copy link
Copy Markdown
Contributor

@cnaples79 cnaples79 commented Feb 1, 2026

Summary

  • only treat clicks outside the dialog bounds as light dismiss
  • avoid closing modals when clicking padding or title areas

Rationale

Changes

  • app/app.vue: check click coordinates against dialog bounding box before closing

Test Plan

  • All CI passing on fork

Fixes #667

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 2, 2026 11:12am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 2, 2026 11:12am
npmx-lunaria Ignored Ignored Feb 2, 2026 11:12am

Request Review

@knowler
Copy link
Copy Markdown
Member

knowler commented Feb 1, 2026

So, the particular code that is causing this is a hack to add light dismiss to Safari (see #522 for context). I suggest that we feature check closedby=any which does the light dismiss for us for free and then keep the hack for cases where closedby=any isn’t supported (Safari + old Chrome/Firefox).

You can feature check closedby=any using:

typeof HTMLDialogElement !== "undefined" &&
typeof HTMLDialogElement.prototype === "object" &&
"closedBy" in HTMLDialogElement.prototype

Feel free to simply that to the final condition if this code will only run in a browser.

I said this in #522, but I do think it could be worth removing the hack entirely if it’s causing issues or not working correctly. Users can already dismiss the modal using the Escape key or with the dismiss button; light dismiss is a progressive enhancement. This is likely a better route than keeping it as light dismiss is not easy to implement with dialog otherwise.

@danielroe
Copy link
Copy Markdown
Member

yes, I think that's a better fix - thank you 🙏

@danielroe danielroe enabled auto-merge February 2, 2026 11:09
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 2, 2026
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 2, 2026
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 2, 2026
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 2, 2026
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
Merged via the queue into npmx-dev:main with commit 17c4a75 Feb 2, 2026
13 checks passed
taskylizard pushed a commit to taskylizard/npmx.dev that referenced this pull request Feb 7, 2026
Co-authored-by: Daniel Roe <daniel@roe.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dialogs can be closed by clicking within some areas of the dialog itself

3 participants