fix(ui/overlays): overlay growing margin (#2331)

This commit is contained in:
ka9de 2024-08-28 13:59:48 +02:00 committed by GitHub
parent c6a8d6d754
commit bca25bc41e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
fix: [overlays] avoid growing margin when using `preventsScroll: false`

View file

@ -788,6 +788,10 @@ export class OverlayController extends EventTarget {
* @protected
*/
_keepBodySize({ phase }) {
if (!this.preventsScroll) {
return;
}
switch (phase) {
case 'before-show':
this.__bodyClientWidth = document.body.clientWidth;

View file

@ -1781,4 +1781,33 @@ describe('OverlayController', () => {
);
});
});
describe('run _keepBodySize only with scroll prevention', () => {
/**
* @type {OverlayController}
*/
const overlayControllerNoPrevent = new OverlayController({
...withLocalTestConfig(),
preventsScroll: false,
});
const overlayControllerPreventsScroll = new OverlayController({
...withLocalTestConfig(),
preventsScroll: true,
});
it('should not run with scroll prevention', async () => {
await overlayControllerNoPrevent.show();
expect(overlayControllerNoPrevent.__bodyMarginRightInline).to.equal(undefined);
expect(overlayControllerNoPrevent.__bodyMarginRight).to.equal(undefined);
});
it('should run with scroll prevention', async () => {
await overlayControllerPreventsScroll.show();
expect(overlayControllerPreventsScroll.__bodyMarginRightInline).to.not.equal(undefined);
expect(overlayControllerPreventsScroll.__bodyMarginRight).to.not.equal(undefined);
});
});
});