fix(overlays): clicking outside iframe not closing the overlay

This commit is contained in:
Gyulai Levente 2024-11-12 17:24:21 +01:00 committed by GitHub
parent a19096e703
commit 2a989f47cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
[overlays] now closes when iframe loses focus

View file

@ -1285,6 +1285,14 @@ export class OverlayController extends EventTarget {
wasMouseUpInside = false;
});
};
/** @type {EventListenerOrEventListenerObject} */
this.__onWindowBlur = () => {
// When the current window loses the focus (clicking outside iframe) the overlay gets hidden
setTimeout(() => {
this.hide();
});
};
}
this.contentWrapperNode[addOrRemoveListener](
@ -1321,6 +1329,11 @@ export class OverlayController extends EventTarget {
(this.__onDocumentMouseUp),
true,
);
window[addOrRemoveListener](
'blur',
/** @type {EventListenerOrEventListenerObject} */
(this.__onWindowBlur),
);
}
/**

View file

@ -1092,6 +1092,19 @@ describe('OverlayController', () => {
expect(ctrl.isShown).to.be.true;
});
it('hides when window is blurred (useful for iframes)', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
hidesOnOutsideClick: true,
});
await ctrl.show();
window.dispatchEvent(new Event('blur'));
await aTimeout(0);
expect(ctrl.isShown).to.be.false;
});
});
describe('elementToFocusAfterHide', () => {