Skip to content

feat(drawer): add closedby="any" to prevent backdrop drag-close#5959

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/fix-drawer-mouse-up-event
Draft

feat(drawer): add closedby="any" to prevent backdrop drag-close#5959
Copilot wants to merge 11 commits intomainfrom
copilot/fix-drawer-mouse-up-event

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

  • Understand the issue: Mouse up event on backdrop closes drawer even if mouse down started inside drawer content
  • Understand the solution: Use closedby="any" HTML attribute on dialog elements opened via .showModal()
  • Review browser support: Already documented in BrowserSupport.md (Chrome 134+, Firefox 141+, Safari TBD)
  • Implement: Add conditional closedby="any" attribute to dialog element when opened via .showModal()
  • Add browser capability detection: Only call .close() when browser doesn't support closedBy or when dialog is not a modal
  • Build and verify: All framework outputs (React, Angular, Vue, Stencil) transpiled correctly
  • Refactor: Extract isNotModal() state function for reuse across the component
  • Code review and security scanning: No issues found

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 31, 2026

⚠️ No Changeset found

Latest commit: 2220d24

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This prevents unwanted drawer closing when a mouse down event starts
inside the drawer and the mouse up event occurs outside the drawer
(on the backdrop).

The closedby attribute is conditionally applied only when the dialog
is opened via showModal() (not for position="absolute", backdrop="none",
or variant="inside" configurations).

Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix mouse up event closing drawer unexpectedly feat(drawer): add closedby="closerequest" to prevent backdrop drag-close Jan 31, 2026
Copilot AI requested a review from mfranzke January 31, 2026 09:45
@mfranzke
Copy link
Copy Markdown
Collaborator

@copilot I'm sorry, it wasn't about closedby="closerequest", but closedby="any". Please additionally add a feature / browser capability detection around .close(), that I needed to comment out for the moment.

…ction

- Changed closedby attribute from "closerequest" to "any"
- Added feature detection for closedBy in HTMLDialogElement.prototype
- Only call .close() when browser doesn't support closedBy or dialog is not modal

Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 31, 2026

@copilot I'm sorry, it wasn't about closedby="closerequest", but closedby="any". Please additionally add a feature / browser capability detection around .close(), that I needed to comment out fo...

Done in d9f96b7. Changed closedby from "closerequest" to "any" and added browser capability detection around .close(). The dialog will now only call .close() when:

  • The browser doesn't support closedBy (!('closedBy' in HTMLDialogElement.prototype))
  • OR the dialog is not a modal (position="absolute", backdrop="none", or variant="inside")

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • developer.mozilla.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@mfranzke mfranzke changed the title feat(drawer): add closedby="closerequest" to prevent backdrop drag-close feat(drawer): add closedby="any"` to prevent backdrop drag-close Jan 31, 2026
@mfranzke mfranzke changed the title feat(drawer): add closedby="any"` to prevent backdrop drag-close feat(drawer): add closedby="any" to prevent backdrop drag-close Jan 31, 2026
@nmerget
Copy link
Copy Markdown
Collaborator

nmerget commented Feb 2, 2026

@mfranzke Using the newest features might be okay for a controlled environment internally but we should do it right now for the components. Safari released it 3 month ago...

And closedby isn't released...

Comment on lines +98 to +100
props.position === 'absolute' ||
props.backdrop === 'none' ||
props.variant === 'inside'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this into a state function (e.g. state.isClosable) to reuse it for closedby attribute

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this into a state function (e.g. state.isClosable) to reuse it for closedby attribute

@copilot please take that comment #5959 (comment) into account and implement it for this condition within the whole file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 85809a1. Extracted the modal detection condition into state.isNotModal() function and reused it in three places:

  • handleDialogOpen() for show() vs showModal()
  • handleDialogOpen() for browser capability detection around .close()
  • JSX closedby attribute

@nmerget
Copy link
Copy Markdown
Collaborator

nmerget commented Feb 2, 2026

Can you add a "Test" into the showcases to cover the issue? An automatic one will not work but you can add it to those files:

showcases/react-showcase/src/components/form/index.tsx
showcases/react-showcase/src/components/form/index.tsx
showcases/vue-showcase/src/components/form/Form.vue

@mfranzke
Copy link
Copy Markdown
Collaborator

mfranzke commented Feb 2, 2026

@mfranzke Using the newest features might be okay for a controlled environment internally but we should do it right now for the components. Safari released it 3 month ago...

And closedby isn't released...

closedby is standardized and released in two of the three major browser engines and available for 72.64% of the global users. In specific contexts this number might increase up to 100%.

We could actually integrate it via graceful degradation to our existing JavaScript code, and nobody would get hurt, but a lot of users would benefit from this (and other features).

Move the modal detection condition into a state function `isNotModal()`
to reduce code duplication. The function is now used for:
- Determining show() vs showModal()
- Browser capability detection around .close()
- The closedby attribute

Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

3 participants