Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions addon/components/ivy-tabs-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default class IvyTabsTabComponent extends Component {
@action
handleClick(event) {
event.preventDefault();
this.select();
if (this.args.tabList.isRegistered(this)) {
this.select();
}
}

get href() {
Expand Down Expand Up @@ -116,7 +118,7 @@ export default class IvyTabsTabComponent extends Component {

@action
focus() {
let element = document.getElementById(this.id);
const element = document.getElementById(this.id);
if (element) {
element.focus();
}
Expand Down
33 changes: 17 additions & 16 deletions addon/components/ivy-tabs-tablist.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ let instanceCount = 0;
export default class IvyTabsTabListComponent extends Component {
registerWithTabsContainer = modifier(() => {
this.args.tabsContainer.registerTabList(this);
// if none of the tabs are selected, try to select one
let selected = this.tabs.find((tab) => tab.isSelected);
if (!selected && this.tabs.length > 0) {
this.selectTab();
}
return () => {
this.args.tabsContainer.unregisterTabList(this);
};
Expand Down Expand Up @@ -125,9 +120,14 @@ export default class IvyTabsTabListComponent extends Component {
*/
@action
registerTab(tab) {
this.tabs = this.tabs.concat(tab);
// run this later so that all the tabs are registered before we try to select one
runTask(this, () => {
this.tabs = this.tabs.concat(tab);
this.selectTab();
// if none of the tabs are selected, try to select one
let selected = this.tabs.find((tab) => tab.isSelected);
if (!selected && this.tabs.length > 0) {
this.selectTab();
}
});
}

Expand Down Expand Up @@ -208,8 +208,7 @@ export default class IvyTabsTabListComponent extends Component {
@action
selectTab() {
const selection = this.selection;

if (isNone(selection) || this.tabs.length === 1) {
if (isNone(selection)) {
this.selectTabByIndex(0);
} else {
this.selectTabByModel(selection);
Expand All @@ -225,20 +224,18 @@ export default class IvyTabsTabListComponent extends Component {
selectTabByIndex(index) {
const tab = this.tabs[index];

if (tab && tab.isSelected === false) {
runTask(tab, () => {
tab.select();
});
if (tab) {
tab.select();
}
}

selectTabByModel(model) {
const tab = this.tabs.find((element) => element.model === model);

if (tab) {
runTask(tab, () => {
tab.select();
});
tab.select();
} else {
this.selectTabByIndex(0);
}
}

Expand Down Expand Up @@ -279,4 +276,8 @@ export default class IvyTabsTabListComponent extends Component {
return element !== tab;
});
}

isRegistered(tab) {
return this.tabs.includes(tab);
}
}