fix(overlays): synchronize intercepted opened state OverlayMixin
Co-authored-by: Aymen Ben Amor <Aymen.Ben.Amor@ing.com>
This commit is contained in:
parent
b58aa65377
commit
88d3850d5d
3 changed files with 26 additions and 5 deletions
|
|
@ -86,12 +86,14 @@ export const OverlayMixin = dedupeMixin(
|
|||
updated(changedProperties) {
|
||||
super.updated(changedProperties);
|
||||
|
||||
if (changedProperties.has('opened')) {
|
||||
if (this._overlayCtrl) {
|
||||
if (
|
||||
changedProperties.has('opened') &&
|
||||
this._overlayCtrl &&
|
||||
!this.__blockSyncToOverlayCtrl
|
||||
) {
|
||||
this.__syncToOverlayController();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @overridable
|
||||
|
|
@ -210,6 +212,13 @@ export const OverlayMixin = dedupeMixin(
|
|||
this._overlayCtrl.teardown();
|
||||
}
|
||||
|
||||
async _setOpenedWithoutPropertyEffects(newOpened) {
|
||||
this.__blockSyncToOverlayCtrl = true;
|
||||
this.opened = newOpened;
|
||||
await this.updateComplete;
|
||||
this.__blockSyncToOverlayCtrl = false;
|
||||
}
|
||||
|
||||
__setupSyncFromOverlayController() {
|
||||
this.__onOverlayCtrlShow = () => {
|
||||
this.opened = true;
|
||||
|
|
@ -223,6 +232,8 @@ export const OverlayMixin = dedupeMixin(
|
|||
const event = new CustomEvent('before-opened', { cancelable: true });
|
||||
this.dispatchEvent(event);
|
||||
if (event.defaultPrevented) {
|
||||
// Check whether our current `.opened` state is not out of sync with overlayCtrl
|
||||
this._setOpenedWithoutPropertyEffects(this._overlayCtrl.isShown);
|
||||
beforeShowEvent.preventDefault();
|
||||
}
|
||||
};
|
||||
|
|
@ -231,6 +242,8 @@ export const OverlayMixin = dedupeMixin(
|
|||
const event = new CustomEvent('before-closed', { cancelable: true });
|
||||
this.dispatchEvent(event);
|
||||
if (event.defaultPrevented) {
|
||||
// Check whether our current `.opened` state is not out of sync with overlayCtrl
|
||||
this._setOpenedWithoutPropertyEffects(this._overlayCtrl.isShown);
|
||||
beforeHideEvent.preventDefault();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class DemoOverlaySystem extends OverlayMixin(LitElement) {
|
|||
<slot name="invoker"></slot>
|
||||
<slot name="content"></slot>
|
||||
<slot name="_overlay-shadow-outlet"></slot>
|
||||
<div>popup is ${this.opened ? 'opened' : 'closed'}</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,14 @@ export function runOverlayMixinSuite({ /* tagString, */ tag, suffix = '' }) {
|
|||
<button slot="invoker">invoker button</button>
|
||||
</${tag}>
|
||||
`);
|
||||
await el._overlayCtrl.show();
|
||||
el.querySelector('[slot="invoker"]').click();
|
||||
await nextFrame();
|
||||
expect(el.opened).to.be.false;
|
||||
|
||||
// Also, the opened state should be synced back to that of the OverlayController
|
||||
el.opened = true;
|
||||
expect(el.opened).to.be.true;
|
||||
await nextFrame();
|
||||
expect(el.opened).to.be.false;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue