Skip to content

Commit 47badb2

Browse files
committed
using pfe-id and .pfeId instead of id for analytics reasons
1 parent e53e01e commit 47badb2

File tree

4 files changed

+72
-24
lines changed

4 files changed

+72
-24
lines changed

elements/pfe-accordion/src/pfe-accordion.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ class PfeAccordion extends PFElement {
185185
headers.forEach(header => {
186186
const panel = this._panelForHeader(header);
187187

188-
header.setAttribute("aria-controls", panel.id);
189-
panel.setAttribute("aria-labelledby", header.id);
188+
header.setAttribute("aria-controls", panel.pfeId);
189+
panel.setAttribute("aria-labelledby", header.pfeId);
190190
});
191191
}
192192

@@ -356,6 +356,18 @@ class PfeAccordionHeader extends PFElement {
356356
return "pfe-accordion-header.html";
357357
}
358358

359+
get pfeId() {
360+
return this.getAttribute("pfe-id");
361+
}
362+
363+
set pfeId(id) {
364+
if (!id) {
365+
return;
366+
}
367+
368+
this.setAttribute("pfe-id", id);
369+
}
370+
359371
static get observedAttributes() {
360372
return ["aria-expanded"];
361373
}
@@ -372,8 +384,8 @@ class PfeAccordionHeader extends PFElement {
372384
this.setAttribute("role", "header");
373385
}
374386

375-
if (!this.id) {
376-
this.id = `${PfeAccordionHeader.tag}-${generateId()}`;
387+
if (!this.pfeId) {
388+
this.pfeId = `${PfeAccordionHeader.tag}-${generateId()}`;
377389
}
378390

379391
this.button = this.shadowRoot.querySelector("button");
@@ -456,6 +468,18 @@ class PfeAccordionPanel extends PFElement {
456468
return "pfe-accordion-panel.html";
457469
}
458470

471+
get pfeId() {
472+
return this.getAttribute("pfe-id");
473+
}
474+
475+
set pfeId(id) {
476+
if (!id) {
477+
return;
478+
}
479+
480+
this.setAttribute("pfe-id", id);
481+
}
482+
459483
constructor() {
460484
super(PfeAccordionPanel);
461485
}
@@ -467,8 +491,8 @@ class PfeAccordionPanel extends PFElement {
467491
this.setAttribute("role", "region");
468492
}
469493

470-
if (!this.id) {
471-
this.id = `${PfeAccordionPanel.tag}-${generateId()}`;
494+
if (!this.pfeId) {
495+
this.pfeId = `${PfeAccordionPanel.tag}-${generateId()}`;
472496
}
473497
}
474498

elements/pfe-accordion/test/pfe-accordion_test.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ <h2>Where do the main characters work as adults?</h2>
6868
assert.equal(header.getAttribute('role'), 'header');
6969
assert.isTrue(panel.hasAttribute('aria-labelledby'));
7070
assert.equal(panel.getAttribute('role'), 'region');
71-
assert.equal(header.id, panel.getAttribute('aria-labelledby'));
72-
assert.equal(panel.id, header.getAttribute('aria-controls'));
71+
assert.equal(header.pfeId, panel.getAttribute('aria-labelledby'));
72+
assert.equal(panel.pfeId, header.getAttribute('aria-controls'));
7373
});
7474

7575
test('it should expand a panel when a header is selected', () => {

elements/pfe-tabs/src/pfe-tabs.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ class PfeTabs extends PFElement {
259259
const panel = tab.nextElementSibling;
260260
if (panel.tagName.toLowerCase() !== "pfe-tab-panel") {
261261
console.warn(
262-
`${PfeTabs.tag}: tab #${tab.id} is not a sibling of a <pfe-tab-panel>`
262+
`${PfeTabs.tag}: tab #${tab.pfeId} is not a sibling of a <pfe-tab-panel>`
263263
);
264264
return;
265265
}
266266

267-
tab.setAttribute("aria-controls", panel.id);
268-
panel.setAttribute("aria-labelledby", tab.id);
267+
tab.setAttribute("aria-controls", panel.pfeId);
268+
panel.setAttribute("aria-labelledby", tab.pfeId);
269269

270270
tab.addEventListener("click", this._onClick);
271271
});
@@ -283,7 +283,7 @@ class PfeTabs extends PFElement {
283283

284284
_panelForTab(tab) {
285285
const panelId = tab.getAttribute("aria-controls");
286-
return this.querySelector(`#${panelId}`);
286+
return this.querySelector(`[pfe-id="${panelId}"]`);
287287
}
288288

289289
_prevTab() {
@@ -310,7 +310,7 @@ class PfeTabs extends PFElement {
310310

311311
_getTabIndex(_tab) {
312312
const tabs = this._allTabs();
313-
const index = tabs.findIndex(tab => tab.id === _tab.id);
313+
const index = tabs.findIndex(tab => tab.pfeId === _tab.pfeId);
314314
return index;
315315
}
316316

@@ -329,7 +329,7 @@ class PfeTabs extends PFElement {
329329
let newTabSelected = false;
330330

331331
if (!newPanel) {
332-
throw new Error(`No panel with id ${newPanel.id}`);
332+
throw new Error(`No panel with pfeId ${newPanel.pfeId}`);
333333
}
334334

335335
if (this.selected && this.selected !== newTab) {
@@ -440,11 +440,23 @@ class PfeTab extends PFElement {
440440
super(PfeTab);
441441
}
442442

443+
get pfeId() {
444+
return this.getAttribute("pfe-id");
445+
}
446+
447+
set pfeId(id) {
448+
if (!id) {
449+
return;
450+
}
451+
452+
this.setAttribute("pfe-id", id);
453+
}
454+
443455
connectedCallback() {
444456
super.connectedCallback();
445457

446-
if (!this.id) {
447-
this.id = `${PfeTab.tag}-${generateId()}`;
458+
if (!this.pfeId) {
459+
this.pfeId = `${PfeTab.tag}-${generateId()}`;
448460
}
449461

450462
this.setAttribute("role", "tab");
@@ -484,15 +496,27 @@ class PfeTabPanel extends PFElement {
484496
return "pfe-tab-panel.html";
485497
}
486498

499+
get pfeId() {
500+
return this.getAttribute("pfe-id");
501+
}
502+
503+
set pfeId(id) {
504+
if (!id) {
505+
return;
506+
}
507+
508+
this.setAttribute("pfe-id", id);
509+
}
510+
487511
constructor() {
488512
super(PfeTabPanel);
489513
}
490514

491515
connectedCallback() {
492516
super.connectedCallback();
493517

494-
if (!this.id) {
495-
this.id = `${PfeTabPanel.tag}-${generateId()}`;
518+
if (!this.pfeId) {
519+
this.pfeId = `${PfeTabPanel.tag}-${generateId()}`;
496520
}
497521

498522
this.setAttribute("role", "tabpanel");

elements/pfe-tabs/test/pfe-tabs_test.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ <h2>Content 3</h2>
109109
const tab = rhTabs.querySelector('pfe-tab');
110110
const panel = rhTabs.querySelector('pfe-tab-panel');
111111

112-
assert.isTrue(tab.hasAttribute("id"));
113-
assert.isTrue(panel.hasAttribute("id"));
112+
assert.isTrue(tab.hasAttribute("pfe-id"));
113+
assert.isTrue(panel.hasAttribute("pfe-id"));
114114
assert.equal(rhTabs.getAttribute("role"), "tablist");
115115
assert.equal(tab.getAttribute("role"), "tab");
116116
assert.isTrue(tab.hasAttribute("aria-selected"));
117117
assert.isTrue(tab.hasAttribute("aria-controls"));
118118
assert.equal(panel.getAttribute("role"), "tabpanel");
119119
assert.isTrue(panel.hasAttribute("aria-labelledby"));
120-
assert.equal(tab.id, panel.getAttribute("aria-labelledby"));
121-
assert.equal(tab.getAttribute("aria-controls"), panel.id);
120+
assert.equal(tab.pfeId, panel.getAttribute("aria-labelledby"));
121+
assert.equal(tab.getAttribute("aria-controls"), panel.pfeId);
122122
});
123123

124124
test('it should use the ids that are provided instead of generating new ones', () => {
@@ -202,7 +202,7 @@ <h2>Content 3</h2>
202202
const eventDetail = handlerSpy.getCall(0).args[0].detail;
203203

204204
sinon.assert.calledOnce(handlerSpy);
205-
assert.equal(firstTab.id, eventDetail.tab.id);
205+
assert.equal(firstTab.pfeId, eventDetail.tab.pfeId);
206206

207207
document.removeEventListener('pfe-tabs:hidden-tab', handlerSpy);
208208
done();
@@ -221,7 +221,7 @@ <h2>Content 3</h2>
221221
const eventDetail = handlerSpy.getCall(0).args[0].detail;
222222

223223
sinon.assert.calledOnce(handlerSpy);
224-
assert.equal(secondTab.id, eventDetail.tab.id);
224+
assert.equal(secondTab.pfeId, eventDetail.tab.pfeId);
225225

226226
document.removeEventListener('pfe-tabs:shown-tab', handlerSpy);
227227
done();

0 commit comments

Comments
 (0)