fix(ui/overlays): overlay growing margin (#2331)
This commit is contained in:
parent
c6a8d6d754
commit
bca25bc41e
3 changed files with 38 additions and 0 deletions
5
.changeset/avoid-growing-margin.md
Normal file
5
.changeset/avoid-growing-margin.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: [overlays] avoid growing margin when using `preventsScroll: false`
|
||||||
|
|
@ -788,6 +788,10 @@ export class OverlayController extends EventTarget {
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
_keepBodySize({ phase }) {
|
_keepBodySize({ phase }) {
|
||||||
|
if (!this.preventsScroll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
case 'before-show':
|
case 'before-show':
|
||||||
this.__bodyClientWidth = document.body.clientWidth;
|
this.__bodyClientWidth = document.body.clientWidth;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue