Skip to content

Commit ef0bfb1

Browse files
committed
feat(pat navigationmarker): Also mark the anchor with current and in-path classes. Previously only the wrapper was marked.
1 parent 5d46d28 commit ef0bfb1

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/pat/navigationmarker/navigationmarker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default Base.extend({
3636
: nav_item.parentNode;
3737

3838
if (nav_url === current_url_prepared) {
39+
nav_item.classList.add(this.options.currentClass);
3940
wrapper.classList.add(this.options.currentClass);
4041
} else if (
4142
// Compare the current navigation item url with a slash at the
@@ -45,6 +46,7 @@ export default Base.extend({
4546
// be in the path.
4647
nav_url !== portal_url
4748
) {
49+
nav_item.classList.add(this.options.inPathClass);
4850
wrapper.classList.add(this.options.inPathClass);
4951
} else {
5052
// Not even in path.

src/pat/navigationmarker/navigationmarker.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,63 +76,63 @@ describe("pat-navigationmarker", () => {
7676
const it3 = document.querySelector("a[href='../../path3']");
7777
const it4 = document.querySelector("a[href='https://patternslib.com/path4']");
7878

79-
expect(document.querySelectorAll(".current").length).toBe(1);
79+
expect(document.querySelectorAll(".current").length).toBe(2);
8080
expect(document.querySelectorAll(".inPath").length).toBe(0);
8181
expect(document.querySelector(".current a")).toBe(it0);
8282

8383
instance.clear_items();
8484
instance.mark_items("https://patternslib.com/path1");
8585

86-
expect(document.querySelectorAll(".current").length).toBe(1);
86+
expect(document.querySelectorAll(".current").length).toBe(2);
8787
expect(document.querySelectorAll(".inPath").length).toBe(0);
8888
expect(document.querySelector(".current a")).toBe(it1);
8989

9090
instance.clear_items();
9191
instance.mark_items("https://patternslib.com/path2");
9292

93-
expect(document.querySelectorAll(".current").length).toBe(1);
93+
expect(document.querySelectorAll(".current").length).toBe(2);
9494
expect(document.querySelectorAll(".inPath").length).toBe(0);
9595
expect(document.querySelector(".current a")).toBe(it2);
9696

9797
instance.clear_items();
9898
instance.mark_items("https://patternslib.com/path2/path2.1");
9999

100-
expect(document.querySelectorAll(".current").length).toBe(1);
101-
expect(document.querySelectorAll(".inPath").length).toBe(1);
100+
expect(document.querySelectorAll(".current").length).toBe(2);
101+
expect(document.querySelectorAll(".inPath").length).toBe(2);
102102
expect(document.querySelector(".current a")).toBe(it21);
103103

104104
instance.clear_items();
105105
instance.mark_items("https://patternslib.com/path2/path2.2");
106106

107-
expect(document.querySelectorAll(".current").length).toBe(1);
108-
expect(document.querySelectorAll(".inPath").length).toBe(1);
107+
expect(document.querySelectorAll(".current").length).toBe(2);
108+
expect(document.querySelectorAll(".inPath").length).toBe(2);
109109
expect(document.querySelector(".current a")).toBe(it22);
110110

111111
instance.clear_items();
112112
instance.mark_items("https://patternslib.com/path2/path2.2/path2.2.1");
113113

114-
expect(document.querySelectorAll(".current").length).toBe(1);
115-
expect(document.querySelectorAll(".inPath").length).toBe(2);
114+
expect(document.querySelectorAll(".current").length).toBe(2);
115+
expect(document.querySelectorAll(".inPath").length).toBe(4);
116116
expect(document.querySelector(".current a")).toBe(it221);
117117

118118
instance.clear_items();
119119
instance.mark_items("https://patternslib.com/path2/path2.2/path2.2.2");
120120

121-
expect(document.querySelectorAll(".current").length).toBe(1);
122-
expect(document.querySelectorAll(".inPath").length).toBe(2);
121+
expect(document.querySelectorAll(".current").length).toBe(2);
122+
expect(document.querySelectorAll(".inPath").length).toBe(4);
123123
expect(document.querySelector(".current a")).toBe(it222);
124124

125125
instance.clear_items();
126126
instance.mark_items("https://patternslib.com/path3");
127127

128-
expect(document.querySelectorAll(".current").length).toBe(1);
128+
expect(document.querySelectorAll(".current").length).toBe(2);
129129
expect(document.querySelectorAll(".inPath").length).toBe(0);
130130
expect(document.querySelector(".current a")).toBe(it3);
131131

132132
instance.clear_items();
133133
instance.mark_items("https://patternslib.com/path4");
134134

135-
expect(document.querySelectorAll(".current").length).toBe(1);
135+
expect(document.querySelectorAll(".current").length).toBe(2);
136136
expect(document.querySelectorAll(".inPath").length).toBe(0);
137137
expect(document.querySelector(".current a")).toBe(it4);
138138
});

0 commit comments

Comments
 (0)