Skip to content

Commit 6e3b6dd

Browse files
authored
Merge pull request #1024 from Patternslib/fix-scroll-box-elastic-scrolling
Fix scroll box elastic scrolling
2 parents 640d20d + 596fd06 commit 6e3b6dd

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/pat/scroll-box/documentation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Ho(horizontal scrolling is not yet supported.
88

99
The classes are:
1010

11-
- `scroll-up`: when scrolling upwards,
12-
- `scroll-down`: when scrolling downwards,
11+
- `scroll-up`: when scrolling upwards - the class is kept even after scrolling has stopped,
12+
- `scroll-down`: when scrolling downwards - the class is kept even after scrolling has stopped,
13+
- `scrolling-up`: when scrolling upwards - this class is removed after scrolling has stopped,
14+
- `scrolling-down`: when scrolling downwards - this class is removed after scrolling has stopped,
1315
- `scroll-position-top`: when the scrolling container is scrolled to the top,
1416
- `scroll-position-bottom`: when the scrolling container is scrolled to the bottom.

src/pat/scroll-box/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
height: 200vh;
1616
}
1717

18+
.container {
19+
/**
20+
* trick to espatblish a relative containing block
21+
* for position:fixed
22+
* See: https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed
23+
*/
24+
transform: rotate(0);
25+
}
26+
1827
body .pat-scroll-box {
1928
overflow-y: auto;
2029
border: 1px solid black;
@@ -49,8 +58,10 @@
4958
</style>
5059
</head>
5160
<body class="pat-scroll-box">
61+
<div class="container">
5262
<div class="pat-scroll-box">
53-
<div class="pat-scroll-box--inner">hello.</div>
63+
<div class="pat-scroll-box--inner">hello.</div>
5464
</div>
65+
</div>
5566
</body>
5667
</html>

src/pat/scroll-box/scroll-box.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ export default Base.extend({
6262
const to_add = [];
6363

6464
if (scroll_pos < this.last_known_scroll_position) {
65-
to_add.push("scroll-up");
6665
to_add.push("scroll-up");
6766
to_add.push("scrolling-up");
6867
} else if (this.last_known_scroll_position < scroll_pos) {
6968
to_add.push("scroll-down");
7069
to_add.push("scrolling-down");
7170
}
7271

73-
if (scroll_pos === 0) {
72+
if (scroll_pos <= 0) {
7473
to_add.push("scroll-position-top");
7574
} else if (
7675
this.scroll_listener === window &&
@@ -101,6 +100,8 @@ export default Base.extend({
101100
},
102101

103102
clear_scrolling_classes() {
103+
// Remove ``scrolling-up`` and ``scrolling-down``
104+
// but keep ``scroll-up`` and ``scroll-down``.
104105
this.el.classList.remove("scrolling-up", "scrolling-down");
105106
},
106107

src/pat/scroll-box/scroll-box.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ describe("pat-scroll-box", function () {
6969
expect(el.classList).not.toContain("scrolling-up");
7070
expect(el.classList).toContain("scrolling-down");
7171

72+
el.scrollTop = 250; // overscrolling / elastic scrolling in Safari
73+
el.dispatchEvent(events.scroll_event());
74+
await utils.animation_frame();
75+
expect(el.classList).not.toContain("scroll-position-top");
76+
expect(el.classList).toContain("scroll-position-bottom");
77+
expect(el.classList).not.toContain("scroll-up");
78+
expect(el.classList).toContain("scroll-down");
79+
expect(el.classList).not.toContain("scrolling-up");
80+
expect(el.classList).toContain("scrolling-down");
81+
7282
el.scrollTop = 0;
7383
el.dispatchEvent(events.scroll_event());
7484
await utils.animation_frame();
@@ -79,7 +89,19 @@ describe("pat-scroll-box", function () {
7989
expect(el.classList).toContain("scrolling-up");
8090
expect(el.classList).not.toContain("scrolling-down");
8191

92+
el.scrollTop = -50; // overscrolling / elastic scrolling in Safari
93+
el.dispatchEvent(events.scroll_event());
94+
await utils.animation_frame();
95+
expect(el.classList).toContain("scroll-position-top");
96+
expect(el.classList).not.toContain("scroll-position-bottom");
97+
expect(el.classList).toContain("scroll-up");
98+
expect(el.classList).not.toContain("scroll-down");
99+
expect(el.classList).toContain("scrolling-up");
100+
expect(el.classList).not.toContain("scrolling-down");
101+
82102
// Test for clearing the scrolling classes after a scroll stop
103+
// scroll-up and scroll-down are not cleared.
104+
83105
// Still there...
84106
await utils.timeout(custom_timeout / 2);
85107
expect(el.classList).toContain("scrolling-up");

0 commit comments

Comments
 (0)