fix(overlays): clicking outside iframe not closing the overlay
This commit is contained in:
parent
a19096e703
commit
2a989f47cf
3 changed files with 31 additions and 0 deletions
5
.changeset/spotty-penguins-taste.md
Normal file
5
.changeset/spotty-penguins-taste.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
[overlays] now closes when iframe loses focus
|
||||||
|
|
@ -1285,6 +1285,14 @@ export class OverlayController extends EventTarget {
|
||||||
wasMouseUpInside = false;
|
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](
|
this.contentWrapperNode[addOrRemoveListener](
|
||||||
|
|
@ -1321,6 +1329,11 @@ export class OverlayController extends EventTarget {
|
||||||
(this.__onDocumentMouseUp),
|
(this.__onDocumentMouseUp),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
window[addOrRemoveListener](
|
||||||
|
'blur',
|
||||||
|
/** @type {EventListenerOrEventListenerObject} */
|
||||||
|
(this.__onWindowBlur),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1092,6 +1092,19 @@ describe('OverlayController', () => {
|
||||||
|
|
||||||
expect(ctrl.isShown).to.be.true;
|
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', () => {
|
describe('elementToFocusAfterHide', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue