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

bug: prevent overlay click outside to close when clicking on an alert #316

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all 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
14 changes: 9 additions & 5 deletions packages/overlays/src/components/overlay.gts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { cssTransition } from 'ember-css-transitions';
import { useStyles } from '@frontile/theme';
import { modifier } from 'ember-modifier';
// @ts-ignore

Check warning on line 10 in packages/overlays/src/components/overlay.gts

View workflow job for this annotation

GitHub Actions / Tests

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
import { focusTrap } from 'ember-focus-trap';
import onClickOutside from 'ember-click-outside/modifiers/on-click-outside';
import { Backdrop, type BackdropSignature } from './backdrop';
Expand All @@ -29,17 +29,21 @@
return false;
}

// finds if the el has a parent with the id `ember-basic-dropdown-wormhole`
function hasWormholeParentElement(el: HTMLElement) {
// finds if the el has a parent with the id `ember-basic-dropdown-wormhole` or a role of `alert`
function hasWormholeOrAlertParentElement(el: HTMLElement) {
let parent = el.parentElement;
while (parent) {
if (parent.id === 'ember-basic-dropdown-wormhole') {
if (
parent.id === 'ember-basic-dropdown-wormhole' ||
parent.role === 'alert'
) {
return true;
}
parent = parent.parentElement;
}
return false;
}

interface Args
extends Pick<PortalSignature['Args'], 'renderInPlace' | 'target'> {
/**
Expand Down Expand Up @@ -163,7 +167,7 @@
event.target === this.contentElement &&
this.mouseDownContentElement == this.contentElement &&
!hasNestedPortals(this.contentElement) &&
!hasWormholeParentElement(event.target as HTMLElement)
!hasWormholeOrAlertParentElement(event.target as HTMLElement)
) {
this.handleClose();
}
Expand All @@ -175,7 +179,7 @@
this.args.closeOnOutsideClick !== false &&
this.contentElement &&
!hasNestedPortals(this.contentElement) &&
!hasWormholeParentElement(e.target as HTMLElement)
!hasWormholeOrAlertParentElement(e.target as HTMLElement)
) {
this.handleClose();
e.preventDefault();
Expand Down
Loading