Skip to content

Commit 16bc8a2

Browse files
committed
feat(pat navigation): Always set in-path classes.
When doing URL based checkings do always set the in-path classes for an active submenu item, even if it does not match the URL path hierachy.
1 parent 9a0f7a3 commit 16bc8a2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/pat/navigation/navigation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export default Base.extend({
163163
if (nav_url === current_url_prepared) {
164164
nav_item.classList.add(this.options.currentClass);
165165
wrapper.classList.add(this.options.currentClass);
166+
this.mark_in_path(nav_item);
166167
} else if (
167168
// Compare the current navigation item url with a slash at the
168169
// end - if it is "inPath" it must have a slash in it.

src/pat/navigation/navigation.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ describe("Navigation pattern tests - Mark items based on URL", () => {
252252
</li>
253253
</ul>
254254
</li>
255+
<li>
256+
<a href="/i-do-not-math-the-url-path-hierachy">p2n</a>
257+
</li>
255258
</ul>
256259
</li>
257260
<li>
@@ -275,6 +278,7 @@ describe("Navigation pattern tests - Mark items based on URL", () => {
275278
const it22 = document.querySelector("a[href='/path2/path2.2']");
276279
const it221 = document.querySelector("a[href='/path2/path2.2/path2.2.1']");
277280
const it222 = document.querySelector("a[href='/path2/path2.2/path2.2.2']");
281+
const it2n = document.querySelector("a[href='/i-do-not-math-the-url-path-hierachy']"); // prettier-ignore
278282
const it3 = document.querySelector("a[href='../../path3']");
279283
const it4 = document.querySelector("a[href='https://patternslib.com/path4']");
280284

@@ -324,6 +328,15 @@ describe("Navigation pattern tests - Mark items based on URL", () => {
324328
expect(document.querySelectorAll(".inPath").length).toBe(4);
325329
expect(document.querySelector(".current a")).toBe(it222);
326330

331+
instance.clear_items();
332+
instance.mark_items_url(
333+
"https://patternslib.com/i-do-not-math-the-url-path-hierachy"
334+
);
335+
336+
expect(document.querySelectorAll(".current").length).toBe(2);
337+
expect(document.querySelectorAll(".inPath").length).toBe(2);
338+
expect(document.querySelector(".current a")).toBe(it2n);
339+
327340
instance.clear_items();
328341
instance.mark_items_url("https://patternslib.com/path3");
329342

0 commit comments

Comments
 (0)