`Modal`: fix issue with click outside to dismiss
:pushpin: Summary
If merged this PR would update Modal to not use ember-focus-trap to dismiss the Modal on click outside and instead use our own click event.
It also fixes an issue where the scroll bar would get added back if try to close the modal when isDismissDisabled=true.
:hammer_and_wrench: Detailed description
This is necessary because the ember-focus-trap's clickOutSideDeactivates only ever runs once. If a consumer conditionally disables the ability to dismiss the modal, the user may not be able to click outside to deactivate it.
Steps to reproduce:
- Navigate to: https://hds-showcase.vercel.app/components/modal#demo
- Click "Open non-dismissable modal"
- Click outside the modal after it opens, notice it doesn't close and you are able to scroll the page behind the modal.
- Click "reset isDismissDisabled"
- Click outside the modal, notice it doesnt close.
- Click "confirm"/"Cancel"/"close", notice the modal does close.
:link: External links
Jira ticket: HDS-3972
👀 Component checklist
- [x] Percy was checked for any visual regression
- [x] A changelog entry was added via Changesets if needed (see templates here)
:speech_balloon: Please consider using conventional comments when reviewing this PR.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated (UTC) |
|---|---|---|---|
| hds-showcase | ✅ Ready (Inspect) | Visit Preview | May 6, 2025 5:24pm |
| hds-website | ✅ Ready (Inspect) | Visit Preview | May 6, 2025 5:24pm |
It's quite a complex PR with potential side-effects. Maybe @RobbieTheWagner could review it too?
Have you considered moving the logic out of the modal and into a global on-click-outside modifier? Might be a useful modifier to ship with HDS.
Have you considered moving the logic out of the modal and into a global
on-click-outsidemodifier? Might be a useful modifier to ship with HDS.
I like this idea. FWIW, there is a well maintained addon for this, if we want to just use that https://github.com/lifeart/ember-click-outside-modifier
Have you considered moving the logic out of the modal and into a global
on-click-outsidemodifier? Might be a useful modifier to ship with HDS.I like this idea. FWIW, there is a well maintained addon for this, if we want to just use that https://github.com/lifeart/ember-click-outside-modifier
@RobbieTheWagner @zamoore This is definitely an interesting idea... I think for now because there really is only one use so far I'm leaning towards leaving the one off implementation. We usually rely on ember-focus-trap for this functionality, so I don't want to add another dependency.