Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(overlay-mixin): remove scroll lock on ios and mac #2478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-buckets-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lion/ui": patch
---

fix(overlay-mixin): remove scroll lock on ios and mac
18 changes: 0 additions & 18 deletions packages/ui/components/overlays/src/OverlaysManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { browserDetection } from '@lion/ui/core.js';

/**
* @typedef {import('lit').CSSResult} CSSResult
* @typedef {import('./OverlayController.js').OverlayController} OverlayController
Expand Down Expand Up @@ -171,17 +169,8 @@ export class OverlaysManager {

// eslint-disable-next-line class-methods-use-this
requestToPreventScroll() {
const { isIOS, isMacSafari } = browserDetection;
// no check as classList will dedupe it anyways
document.body.classList.add('overlays-scroll-lock');
if (isIOS || isMacSafari) {
// iOS and safar for mac have issues with overlays with input fields. This is fixed by applying
// position: fixed to the body. As a side effect, this will scroll the body to the top.
document.body.classList.add('overlays-scroll-lock-ios-fix');
}
if (isIOS) {
document.documentElement.classList.add('overlays-scroll-lock-ios-fix');
}
}

requestToEnableScroll() {
Expand All @@ -192,14 +181,7 @@ export class OverlaysManager {
return;
}

const { isIOS, isMacSafari } = browserDetection;
document.body.classList.remove('overlays-scroll-lock');
if (isIOS || isMacSafari) {
document.body.classList.remove('overlays-scroll-lock-ios-fix');
}
if (isIOS) {
document.documentElement.classList.remove('overlays-scroll-lock-ios-fix');
}
}

/**
Expand Down
9 changes: 0 additions & 9 deletions packages/ui/components/overlays/src/overlayDocumentStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@ export const overlayDocumentStyle = css`
body.overlays-scroll-lock {
overflow: hidden;
}

body.overlays-scroll-lock-ios-fix {
position: fixed;
width: 100%;
}

html.overlays-scroll-lock-ios-fix {
height: 100vh;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
html,
} from '@open-wc/testing';
import { overlays as overlaysManager, OverlayController } from '@lion/ui/overlays.js';
import { browserDetection } from '@lion/ui/core.js';
import { cache } from 'lit/directives/cache.js';
import '@lion/ui/define/lion-dialog.js';
import { LitElement } from 'lit';
Expand Down Expand Up @@ -103,10 +102,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
)
);

// For now, we skip this test for MacSafari, since the body.overlays-scroll-lock-ios-fix
// class results in a scrollbar when preventsScroll is true.
// However, fully functioning interacive elements (input fields) in the dialog are more important
if (browserDetection.isMacSafari && elWithBigParent._overlayCtrl.preventsScroll) {
if (elWithBigParent._overlayCtrl.preventsScroll) {
return;
}

Expand Down
67 changes: 0 additions & 67 deletions packages/ui/components/overlays/test/OverlaysManager.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { expect, fixture } from '@open-wc/testing';
import { html } from 'lit/static-html.js';
import sinon from 'sinon';
import { browserDetection } from '@lion/ui/core.js';
import { OverlayController, OverlaysManager } from '@lion/ui/overlays.js';

/**
Expand Down Expand Up @@ -100,69 +98,4 @@ describe('OverlaysManager', () => {
await dialog2.hide();
expect(mngr.shownList).to.deep.equal([]);
});

describe('Browser/device edge cases', () => {
const isIOSDetectionStub = sinon.stub(browserDetection, 'isIOS');
const isMacSafariDetectionStub = sinon.stub(browserDetection, 'isMacSafari');

function mockIOS() {
isIOSDetectionStub.value(true);
isMacSafariDetectionStub.value(false);
}

function mockMacSafari() {
// When we are iOS
isIOSDetectionStub.value(false);
isMacSafariDetectionStub.value(true);
}

afterEach(() => {
// Restore original values
isIOSDetectionStub.restore();
isMacSafariDetectionStub.restore();
});

describe('When initialized with "preventsScroll: true"', () => {
it('adds class "overlays-scroll-lock-ios-fix" to body and html on iOS', async () => {
mockIOS();
const dialog = new OverlayController({ ...defaultOptions, preventsScroll: true }, mngr);
await dialog.show();
expect(Array.from(document.body.classList)).to.contain('overlays-scroll-lock-ios-fix');
expect(Array.from(document.documentElement.classList)).to.contain(
'overlays-scroll-lock-ios-fix',
);
await dialog.hide();
expect(Array.from(document.body.classList)).to.not.contain('overlays-scroll-lock-ios-fix');
expect(Array.from(document.documentElement.classList)).to.not.contain(
'overlays-scroll-lock-ios-fix',
);

// When we are not iOS nor MacSafari
isIOSDetectionStub.value(false);
isMacSafariDetectionStub.value(false);

const dialog2 = new OverlayController({ ...defaultOptions, preventsScroll: true }, mngr);
await dialog2.show();
expect(Array.from(document.body.classList)).to.not.contain('overlays-scroll-lock-ios-fix');
expect(Array.from(document.documentElement.classList)).to.not.contain(
'overlays-scroll-lock-ios-fix',
);
});

it('adds class "overlays-scroll-lock-ios-fix" to body on MacSafari', async () => {
mockMacSafari();
const dialog = new OverlayController({ ...defaultOptions, preventsScroll: true }, mngr);
await dialog.show();
expect(Array.from(document.body.classList)).to.contain('overlays-scroll-lock-ios-fix');
expect(Array.from(document.documentElement.classList)).to.not.contain(
'overlays-scroll-lock-ios-fix',
);
await dialog.hide();
expect(Array.from(document.body.classList)).to.not.contain('overlays-scroll-lock-ios-fix');
expect(Array.from(document.documentElement.classList)).to.not.contain(
'overlays-scroll-lock-ios-fix',
);
});
});
});
});