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

feat: dispatch an event after overlay closing completed #5397

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 0 additions & 12 deletions packages/confirm-dialog/src/vaadin-confirm-dialog-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,6 @@ class ConfirmDialogOverlay extends DialogOverlay {
return memoizedTemplate;
}

/**
* Override method inherited from `Overlay` to notify when overlay is closed.
* The `vaadin-overlay-close` event is not suitable, as it fires before closing.
* @protected
* @override
*/
_finishClosing() {
super._finishClosing();

this.dispatchEvent(new CustomEvent('vaadin-confirm-dialog-close'));
}

/**
* @protected
* @override
Expand Down
2 changes: 1 addition & 1 deletion packages/confirm-dialog/src/vaadin-confirm-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class ConfirmDialog extends ElementMixin(ThemePropertyMixin(ControllerMixin(Poly
this._overlayElement = this.$.dialog.$.overlay;
this._overlayElement.addEventListener('vaadin-overlay-escape-press', this._escPressed.bind(this));
this._overlayElement.addEventListener('vaadin-overlay-open', () => this.__onDialogOpened());
this._overlayElement.addEventListener('vaadin-confirm-dialog-close', () => this.__onDialogClosed());
this._overlayElement.addEventListener('vaadin-overlay-closed', () => this.__onDialogClosed());

this._headerController = new SlotController(this, 'header', 'h3', {
initializer: (node) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/overlay/src/vaadin-overlay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export type OverlayOpenEvent = CustomEvent;
*/
export type OverlayCloseEvent = CustomEvent;

/**
* Fired after the overlay is closed.
*/
export type OverlayClosedEvent = CustomEvent;

/**
* Fired when the overlay will be closed.
*/
Expand All @@ -46,6 +51,7 @@ export interface OverlayCustomEventMap {
'opened-changed': OverlayOpenedChangedEvent;
'vaadin-overlay-open': OverlayOpenEvent;
'vaadin-overlay-close': OverlayCloseEvent;
'vaadin-overlay-closed': OverlayClosedEvent;
'vaadin-overlay-closing': OverlayClosingEvent;
'vaadin-overlay-outside-click': OverlayOutsideClickEvent;
'vaadin-overlay-escape-press': OverlayEscapePressEvent;
Expand Down Expand Up @@ -108,6 +114,7 @@ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
* @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
* @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
* @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
* @fires {CustomEvent} vaadin-overlay-closed - Fired after the overlay is closed.
* @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay will be closed on outside click. If canceled the closing of the overlay is canceled as well.
* @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/overlay/src/vaadin-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
* @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
* @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
* @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
* @fires {CustomEvent} vaadin-overlay-closed - Fired after the overlay is closed.
* @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay will be closed on outside click. If canceled the closing of the overlay is canceled as well.
* @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
*
Expand Down Expand Up @@ -598,6 +599,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
this._detachOverlay();
this.$.overlay.style.removeProperty('pointer-events');
this.removeAttribute('closing');
this.dispatchEvent(new CustomEvent('vaadin-overlay-closed'));
}

/**
Expand Down Expand Up @@ -793,6 +795,11 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
this.style.zIndex = zIndex;
this.__zIndex = zIndex || parseFloat(getComputedStyle(this).zIndex);
}

/**
* @event vaadin-overlay-closed
* Fired after the overlay is closed.
*/
}

customElements.define(Overlay.is, Overlay);
Expand Down
22 changes: 22 additions & 0 deletions packages/overlay/test/overlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ describe('vaadin-overlay', () => {
});
});

describe('vaadin-overlay-closed event', () => {
it('should dispatch vaadin-overlay-closed after the overlay has closed', () => {
const closingSpy = sinon.spy();
overlay.addEventListener('vaadin-overlay-closing', closingSpy);

const closedSpy = sinon.spy();
overlay.addEventListener('vaadin-overlay-closed', closedSpy);

click(parent);
expect(closedSpy.calledOnce).to.be.true;
expect(closedSpy.calledAfter(closingSpy)).to.be.true;
});

it('should not dispatch vaadin-overlay-closed when preventing vaadin-overlay-close', () => {
const spy = sinon.spy();
overlay.addEventListener('vaadin-overlay-closed', spy);
overlay.addEventListener('vaadin-overlay-close', (e) => e.preventDefault());
click(parent);
expect(spy.called).to.be.false;
});
});

describe('moving mouse pointer during click', () => {
it('should close if both mousedown and mouseup outside', () => {
mousedown(parent);
Expand Down