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: simplified checking scrollability of the element (closes #6601) #6937

Merged
merged 3 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/core/utils/shared/scroll.ts
Expand Up @@ -2,7 +2,7 @@ import adapter from './adapter/index';
import AxisValues from '../../../../shared/utils/values/axis-values';


const SCROLLABLE_OVERFLOW_STYLE_RE = /auto|scroll/i;
const SCROLLABLE_OVERFLOW_STYLE_RE = /auto|scroll|hidden/i;
const DEFAULT_IE_SCROLLABLE_OVERFLOW_STYLE_VALUE = 'visible';

function getScrollable (el: Element): AxisValues<boolean> {
Expand Down Expand Up @@ -40,7 +40,7 @@ function hasBodyScroll (el: HTMLBodyElement): boolean {
}

return (scrollableHorizontally || scrollableVertically) &&
bodyScrollHeight > documentElement.scrollHeight;
bodyScrollHeight > documentElement.scrollHeight;
}

function hasHTMLElementScroll (el: HTMLHtmlElement): boolean {
Expand Down
Expand Up @@ -20,6 +20,13 @@
border: 1px solid black;
}

#hidden {
height: 500px;
width: 500px;
overflow: hidden;
border: 1px solid black;
}

#scrollable-deferred {
height: 500px;
width: 500px;
Expand All @@ -41,6 +48,15 @@
left: 700px;
position: absolute;
}

#hidden-target {
width: 1000px;
height: 1000px;
background-color: black;
top: 700px;
left: 700px;
position: absolute;
}
</style>
</head>
<body>
Expand All @@ -50,6 +66,11 @@
<div id="target"></div>
</div>
</div>
<div id="hidden">
<div style="height: 5000px; width: 5000px; position: relative;">
<div id="hidden-target"></div>
</div>
</div>
</div>
<script>
setTimeout(function () {
Expand Down
Expand Up @@ -23,9 +23,11 @@ fixture `Scroll/ScrollBy/ScrollIntoView`

const selectorHTML = Selector(() => document.scrollingElement || document.documentElement);
const selectorScrollable = Selector('#scrollable');
const selectorHidden = Selector('#hidden');
const selectorScrollableDeferred = Selector('#scrollable-deferred');

const target = Selector('#target');
const target = Selector('#target');
const hiddenTarget = Selector('#hidden-target');

async function assert (t, selector, expected) {
const actual = await getScrollPosition(selector)();
Expand Down Expand Up @@ -179,6 +181,9 @@ test('scroll into view', async t => {

await t.scrollIntoView(target, { offsetX: 1, offsetY: -1 });
await t.expect(getScrollPosition(selectorScrollable)()).eql({ left: 652, top: 1248 });

await t.scrollIntoView(hiddenTarget);
await t.expect(getScrollPosition(selectorHidden)()).eql({ left: 749, top: 749 });
});

test('scroll/scrollby options', async t => {
Expand Down