Skip to content

Commit 76ae658

Browse files
committed
feat: Add nav-label functionality
1 parent 0a861a9 commit 76ae658

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

elements/pfe-jump-links/demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ <h4 slot="pfe-jump-links-nav--heading">Jump to section</h4>
104104
<div class="pfe-l-grid__item pfe-m-12-col pfe-m-9-col-on-lg">
105105
<pfe-jump-links-panel class="special" pfe-c-scrolltarget="jumplinks1">
106106
<div>
107-
<h1 class="pfe-jump-links-panel__section" id="section1">Section 1</h1>
107+
<h1 class="pfe-jump-links-panel__section" id="section1" nav-label="First section">Section 1</h1>
108108
<p>Lorem ipsum dolor amet umami vaporware actually church-key keytar, hell of roof party unicorn helvetica
109109
lomo pop-up fam taxidermy food truck dolore. Crucifix quinoa af eiusmod try-hard velit aesthetic freegan
110110
seitan readymade vinyl snackwave four dollar toast neutra. In ipsum blog tbh. Authentic la croix bespoke

elements/pfe-jump-links/src/pfe-jump-links.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,32 @@ class PfeJumpLinksNav extends PFElement {
168168

169169
for (let i = 0; i < panelSections.length; i++) {
170170
let arr = [...panelSections];
171-
if (arr[i].classList.contains("has-sub-section")) {
171+
let section = arr[i];
172+
let text = section.innerHTML;
173+
// If a custom label was provided, use that instead
174+
if (section.hasAttribute("nav-label")) {
175+
text = section.getAttribute("nav-label");
176+
}
177+
if (section.classList.contains("has-sub-section")) {
172178
let linkListItem = `
173179
<li class="pfe-jump-links-nav__item">
174180
<a
175181
class="pfe-jump-links-nav__link has-sub-section"
176-
href="#${arr[i].id}"
177-
data-target="${arr[i].id}">
178-
${arr[i].innerHTML}
182+
href="#${section.id}"
183+
data-target="${section.id}">
184+
${text}
179185
</a>
180186
<ul class="sub-nav">
181187
`;
182188
linkList += linkListItem;
183-
} else if (arr[i].classList.contains("sub-section")) {
189+
} else if (section.classList.contains("sub-section")) {
184190
let linkSubItem = `
185191
<li class="pfe-jump-links-nav__item">
186192
<a
187193
class="pfe-jump-links-nav__link sub-section"
188-
href="#${arr[i].id}"
189-
data-target="${arr[i].id}">
190-
${arr[i].innerHTML}
194+
href="#${section.id}"
195+
data-target="${section.id}">
196+
${text}
191197
</a>
192198
</li>`;
193199
if (!arr[i + 1].classList.contains("sub-section")) {
@@ -199,9 +205,9 @@ class PfeJumpLinksNav extends PFElement {
199205
<li class="pfe-jump-links-nav__item">
200206
<a
201207
class="pfe-jump-links-nav__link"
202-
href="#${arr[i].id}"
203-
data-target="${arr[i].id}">
204-
${arr[i].innerHTML}
208+
href="#${section.id}"
209+
data-target="${section.id}">
210+
${text}
205211
</a>
206212
</li>
207213
`;

0 commit comments

Comments
 (0)