Skip to content

Commit

Permalink
fix(ui5-tabcontainer): clicking a tab now always works (#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev committed Apr 29, 2020
1 parent 39bd306 commit dc60609
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions packages/main/src/TabContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,22 @@ class TabContainer extends UI5Element {
}

_onHeaderClick(event) {
if (!tabIsClicked(event.target)) {
const tab = getTab(event.target);
if (!tab) {
return;
}

this._onHeaderItemSelect(event);
this._onHeaderItemSelect(tab);
}

_onHeaderKeyDown(event) {
if (!tabIsClicked(event.target)) {
const tab = getTab(event.target);
if (!tab) {
return;
}

if (isEnter(event)) {
this._onHeaderItemSelect(event);
this._onHeaderItemSelect(tab);
}

// Prevent Scrolling
Expand All @@ -307,12 +309,13 @@ class TabContainer extends UI5Element {
}

_onHeaderKeyUp(event) {
if (!tabIsClicked(event.target)) {
const tab = getTab(event.target);
if (!tab) {
return;
}

if (isSpace(event)) {
this._onHeaderItemSelect(event);
this._onHeaderItemSelect(tab);
}
}

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

_onHeaderItemSelect(event) {
if (!event.target.hasAttribute("disabled")) {
this._onItemSelect(event.target);
_onHeaderItemSelect(tab) {
if (!tab.hasAttribute("disabled")) {
this._onItemSelect(tab);
}
}

Expand Down Expand Up @@ -499,8 +502,18 @@ class TabContainer extends UI5Element {
}
}

const tabIsClicked = el => {
return el.localName === "li" && el.getAttribute("role") === "tab";
const isTabLi = el => el.localName === "li" && el.getAttribute("role") === "tab";

const getTab = el => {
while (el) {
if (isTabLi(el)) {
return el;
}

el = el.parentElement;
}

return false;
};

const findIndex = (arr, predicate) => {
Expand Down

0 comments on commit dc60609

Please sign in to comment.