Skip to content

Commit dc60609

Browse files
authored
fix(ui5-tabcontainer): clicking a tab now always works (#1567)
1 parent 39bd306 commit dc60609

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

packages/main/src/TabContainer.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,22 @@ class TabContainer extends UI5Element {
284284
}
285285

286286
_onHeaderClick(event) {
287-
if (!tabIsClicked(event.target)) {
287+
const tab = getTab(event.target);
288+
if (!tab) {
288289
return;
289290
}
290291

291-
this._onHeaderItemSelect(event);
292+
this._onHeaderItemSelect(tab);
292293
}
293294

294295
_onHeaderKeyDown(event) {
295-
if (!tabIsClicked(event.target)) {
296+
const tab = getTab(event.target);
297+
if (!tab) {
296298
return;
297299
}
298300

299301
if (isEnter(event)) {
300-
this._onHeaderItemSelect(event);
302+
this._onHeaderItemSelect(tab);
301303
}
302304

303305
// Prevent Scrolling
@@ -307,12 +309,13 @@ class TabContainer extends UI5Element {
307309
}
308310

309311
_onHeaderKeyUp(event) {
310-
if (!tabIsClicked(event.target)) {
312+
const tab = getTab(event.target);
313+
if (!tab) {
311314
return;
312315
}
313316

314317
if (isSpace(event)) {
315-
this._onHeaderItemSelect(event);
318+
this._onHeaderItemSelect(tab);
316319
}
317320
}
318321

@@ -321,9 +324,9 @@ class TabContainer extends UI5Element {
321324
this._itemNavigation.getItemsCallback = () => this._getTabs();
322325
}
323326

324-
_onHeaderItemSelect(event) {
325-
if (!event.target.hasAttribute("disabled")) {
326-
this._onItemSelect(event.target);
327+
_onHeaderItemSelect(tab) {
328+
if (!tab.hasAttribute("disabled")) {
329+
this._onItemSelect(tab);
327330
}
328331
}
329332

@@ -499,8 +502,18 @@ class TabContainer extends UI5Element {
499502
}
500503
}
501504

502-
const tabIsClicked = el => {
503-
return el.localName === "li" && el.getAttribute("role") === "tab";
505+
const isTabLi = el => el.localName === "li" && el.getAttribute("role") === "tab";
506+
507+
const getTab = el => {
508+
while (el) {
509+
if (isTabLi(el)) {
510+
return el;
511+
}
512+
513+
el = el.parentElement;
514+
}
515+
516+
return false;
504517
};
505518

506519
const findIndex = (arr, predicate) => {

0 commit comments

Comments
 (0)