Skip to content

Commit eb64d81

Browse files
authored
fix: removing stopPropagation from pfe-tabs click and keydown events (#817)
* fix: removing stopPropagation from pfe-tabs click and keydown events Fixes #816 * updating the changelog
1 parent a2cd377 commit eb64d81

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

CHANGELOG-prerelease.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Prerelease 43 ( TBD )
2+
3+
Tag: [v1.0.0-prerelease.43](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.43)
4+
5+
- []() fix: removing stopPropagation from pfe-tabs click and keydown events #817
6+
17
## Prerelease 42 ( 2020-03-31 )
28

39
Tag: [v1.0.0-prerelease.42](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.42)

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,10 @@ class PfeTabs extends PFElement {
388388
}
389389

390390
_onKeyDown(event) {
391-
event.stopPropagation();
391+
const tabs = this._allTabs();
392+
const foundTab = tabs.find(tab => tab === event.target);
392393

393-
if (event.target.getAttribute("role") !== "tab") {
394+
if (!foundTab) {
394395
return;
395396
}
396397

@@ -430,13 +431,14 @@ class PfeTabs extends PFElement {
430431
}
431432

432433
_onClick(event) {
433-
event.stopPropagation();
434+
const tabs = this._allTabs();
435+
const foundTab = tabs.find(tab => tab === event.target);
434436

435-
if (event.currentTarget.getAttribute("role") !== "tab") {
437+
if (!foundTab) {
436438
return;
437439
}
438440

439-
this.selectedIndex = this._getTabIndex(event.currentTarget);
441+
this.selectedIndex = this._getTabIndex(foundTab);
440442
}
441443

442444
_getTabIndexFromURL() {

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ <h2>Content 3</h2>
125125
<pfe-tab role="heading" slot="tab" pfe-id="historyTab2">Tab 1</pfe-tab>
126126
<pfe-tab-panel role="region" slot="panel">Content</pfe-tab-panel>
127127
</pfe-tabs>
128-
128+
129129
<pfe-tabs id="tabs-in-tabs">
130130
<pfe-tab role="heading" slot="tab" id="tabs-in-tabs-1">Tab 1</pfe-tab>
131131
<pfe-tab-panel role="region" slot="panel">
132132
<pfe-tabs id="subtabset">
133133
<pfe-tab role="heading" slot="tab" id="subtab1">Sub Tab 1</pfe-tab>
134134
<pfe-tab-panel role="region" slot="panel">
135135
<h2>Content for Sub Tab 1</h2>
136+
<button id="btn">Button</button>
136137
</pfe-tab-panel>
137138
<pfe-tab role="heading" slot="tab" id="subtab2">Sub Tab 2</pfe-tab>
138139
<pfe-tab-panel role="region" slot="panel" id="subtab2panel">
@@ -147,7 +148,7 @@ <h1>Tab 2 Content</h1>
147148
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
148149
</pfe-tab-panel>
149150
</pfe-tabs>
150-
151+
151152
<script>
152153
suite('<pfe-tabs>', () => {
153154
setup(() => {
@@ -416,12 +417,25 @@ <h1>Tab 2 Content</h1>
416417
flush(() => {
417418
assert.equal(tabset2SubTab2.getAttribute('aria-selected'), 'true');
418419
assert.isTrue(!tabset2SubTabPanel.hasAttribute('hidden'));
419-
420+
420421
done();
421422
});
422423
});
423424
});
424425
});
426+
427+
test("it should not stop events from inside tabs from propagating", () => {
428+
const btn = document.querySelector("#btn");
429+
const handlerSpy = sinon.spy();
430+
431+
document.addEventListener("click", handlerSpy);
432+
btn.click();
433+
434+
const [event] = handlerSpy.getCall(0).args;
435+
sinon.assert.calledOnce(handlerSpy);
436+
437+
document.removeEventListener("click", handlerSpy);
438+
});
425439
});
426440

427441
suite('<pfe-tabs> Tab History', () => {

0 commit comments

Comments
 (0)