Skip to content

Commit 92e1e6b

Browse files
committed
breaking(pat-scroll): Remove implicit and unpreventable scroll support for pat-stacks.
With a pat-scroll as parent of a pat-stacks enabled navigation anchors, the page would scroll to the target configured for pat-scroll. This behavior could not be prevented and led to unwanted effects when using pat-stacks inside pat-collapsible which itself uses pat-scroll when configured properly. This commit removes the scrolling support for pat-stacks within pat-scroll in favor of an explicit and configurable scrolling behavior in pat-stacks itself.
1 parent a7e5de1 commit 92e1e6b

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed

src/pat/scroll/scroll.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import $ from "jquery";
21
import { BasePattern } from "../../core/basepattern";
32
import dom from "../../core/dom";
43
import events from "../../core/events";
@@ -36,15 +35,6 @@ class Pattern extends BasePattern {
3635
if (this.options.trigger === "auto" || this.options.trigger === "click") {
3736
this.el.addEventListener("click", this.scrollTo.bind(this));
3837
}
39-
$(this.el).on("pat-update", this.onPatternsUpdate.bind(this));
40-
}
41-
42-
onPatternsUpdate(ev, data) {
43-
if (data?.pattern === "stacks") {
44-
if (data.originalEvent && data.originalEvent.type === "click") {
45-
this.scrollTo();
46-
}
47-
}
4838
}
4939

5040
get_target() {

src/pat/scroll/scroll.test.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import $ from "jquery";
21
import Pattern from "./scroll";
32
import events from "../../core/events";
43
import utils from "../../core/utils";
@@ -89,25 +88,7 @@ describe("pat-scroll", function () {
8988
expect(this.spy_scrollTo).toHaveBeenCalled();
9089
});
9190

92-
it("5 - will scroll to an anchor on pat-update with originalEvent of click", async function () {
93-
document.body.innerHTML = `
94-
<a href="#p1" class="pat-scroll" data-pat-scroll="trigger: click">p1</a>
95-
<p id="p1"></p>
96-
`;
97-
const $el = $(".pat-scroll");
98-
99-
const instance = new Pattern($el[0]);
100-
await events.await_pattern_init(instance);
101-
$el.trigger("pat-update", {
102-
pattern: "stacks",
103-
originalEvent: {
104-
type: "click",
105-
},
106-
});
107-
expect(this.spy_scrollTo).toHaveBeenCalled();
108-
});
109-
110-
it("6 - will allow for programmatic scrolling with trigger set to 'manual'", async function () {
91+
it("5 - will allow for programmatic scrolling with trigger set to 'manual'", async function () {
11192
document.body.innerHTML = `
11293
<a href="#p1" class="pat-scroll" data-pat-scroll="trigger: manual">p1</a>
11394
<p id="p1"></p>
@@ -124,7 +105,7 @@ describe("pat-scroll", function () {
124105
expect(this.spy_scrollTo).toHaveBeenCalled();
125106
});
126107

127-
it("7 - will scroll to bottom with selector:bottom", async function () {
108+
it("6 - will scroll to bottom with selector:bottom", async function () {
128109
document.body.innerHTML = `
129110
<div id="scroll-container" style="overflow-y: scroll">
130111
<button class="pat-scroll" data-pat-scroll="selector: bottom; trigger: manual">to bottom</button>
@@ -156,7 +137,7 @@ describe("pat-scroll", function () {
156137
expect(container.scrollTop).toBe(1000);
157138
});
158139

159-
it("8 - will add an offset to the scroll position", async function () {
140+
it("7 - will add an offset to the scroll position", async function () {
160141
// Testing with `selector: top`, as this just sets scrollTop to 0
161142

162143
document.body.innerHTML = `
@@ -186,7 +167,7 @@ describe("pat-scroll", function () {
186167
expect(container.scrollTop).toBe(-40);
187168
});
188169

189-
it("9 - will adds a negative offset to scroll position", async function () {
170+
it("8 - will adds a negative offset to scroll position", async function () {
190171
// Testing with `selector: top`, as this just sets scrollTop to 0
191172

192173
document.body.innerHTML = `
@@ -215,7 +196,7 @@ describe("pat-scroll", function () {
215196
expect(container.scrollTop).toBe(40);
216197
});
217198

218-
it("10 - handles different selector options.", async function () {
199+
it("9 - handles different selector options.", async function () {
219200
document.body.innerHTML = `
220201
<a href="#el3" class="pat-scroll">scroll</a>
221202
<div id="el1"></div>

0 commit comments

Comments
 (0)