Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/pat/scroll-box/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Ho(horizontal scrolling is not yet supported.

The classes are:

- `scroll-up`: when scrolling upwards,
- `scroll-down`: when scrolling downwards,
- `scroll-up`: when scrolling upwards - the class is kept even after scrolling has stopped,
- `scroll-down`: when scrolling downwards - the class is kept even after scrolling has stopped,
- `scrolling-up`: when scrolling upwards - this class is removed after scrolling has stopped,
- `scrolling-down`: when scrolling downwards - this class is removed after scrolling has stopped,
- `scroll-position-top`: when the scrolling container is scrolled to the top,
- `scroll-position-bottom`: when the scrolling container is scrolled to the bottom.
13 changes: 12 additions & 1 deletion src/pat/scroll-box/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
height: 200vh;
}

.container {
/**
* trick to espatblish a relative containing block
* for position:fixed
* See: https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed
*/
transform: rotate(0);
}

body .pat-scroll-box {
overflow-y: auto;
border: 1px solid black;
Expand Down Expand Up @@ -49,8 +58,10 @@
</style>
</head>
<body class="pat-scroll-box">
<div class="container">
<div class="pat-scroll-box">
<div class="pat-scroll-box--inner">hello.</div>
<div class="pat-scroll-box--inner">hello.</div>
</div>
</div>
</body>
</html>
5 changes: 3 additions & 2 deletions src/pat/scroll-box/scroll-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ export default Base.extend({
const to_add = [];

if (scroll_pos < this.last_known_scroll_position) {
to_add.push("scroll-up");
to_add.push("scroll-up");
to_add.push("scrolling-up");
} else if (this.last_known_scroll_position < scroll_pos) {
to_add.push("scroll-down");
to_add.push("scrolling-down");
}

if (scroll_pos === 0) {
if (scroll_pos <= 0) {
to_add.push("scroll-position-top");
} else if (
this.scroll_listener === window &&
Expand Down Expand Up @@ -101,6 +100,8 @@ export default Base.extend({
},

clear_scrolling_classes() {
// Remove ``scrolling-up`` and ``scrolling-down``
// but keep ``scroll-up`` and ``scroll-down``.
this.el.classList.remove("scrolling-up", "scrolling-down");
},

Expand Down
22 changes: 22 additions & 0 deletions src/pat/scroll-box/scroll-box.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ describe("pat-scroll-box", function () {
expect(el.classList).not.toContain("scrolling-up");
expect(el.classList).toContain("scrolling-down");

el.scrollTop = 250; // overscrolling / elastic scrolling in Safari
el.dispatchEvent(events.scroll_event());
await utils.animation_frame();
expect(el.classList).not.toContain("scroll-position-top");
expect(el.classList).toContain("scroll-position-bottom");
expect(el.classList).not.toContain("scroll-up");
expect(el.classList).toContain("scroll-down");
expect(el.classList).not.toContain("scrolling-up");
expect(el.classList).toContain("scrolling-down");

el.scrollTop = 0;
el.dispatchEvent(events.scroll_event());
await utils.animation_frame();
Expand All @@ -79,7 +89,19 @@ describe("pat-scroll-box", function () {
expect(el.classList).toContain("scrolling-up");
expect(el.classList).not.toContain("scrolling-down");

el.scrollTop = -50; // overscrolling / elastic scrolling in Safari
el.dispatchEvent(events.scroll_event());
await utils.animation_frame();
expect(el.classList).toContain("scroll-position-top");
expect(el.classList).not.toContain("scroll-position-bottom");
expect(el.classList).toContain("scroll-up");
expect(el.classList).not.toContain("scroll-down");
expect(el.classList).toContain("scrolling-up");
expect(el.classList).not.toContain("scrolling-down");

// Test for clearing the scrolling classes after a scroll stop
// scroll-up and scroll-down are not cleared.

// Still there...
await utils.timeout(custom_timeout / 2);
expect(el.classList).toContain("scrolling-up");
Expand Down