Skip to content

Commit 653c129

Browse files
Merge pull request #57 from jonathannewman/maint/main/avoid-selecting-when-no-specification
(maint) Limit scope and timing of selection
2 parents eda2b42 + be525cf commit 653c129

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

addon/components/ivy-tabs-tab.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ export default class IvyTabsTabComponent extends Component {
5656
@action
5757
handleClick(event) {
5858
event.preventDefault();
59-
this.select();
59+
if (this.args.tabList.isRegistered(this)) {
60+
this.select();
61+
}
6062
}
6163

6264
get href() {
@@ -116,7 +118,7 @@ export default class IvyTabsTabComponent extends Component {
116118

117119
@action
118120
focus() {
119-
let element = document.getElementById(this.id);
121+
const element = document.getElementById(this.id);
120122
if (element) {
121123
element.focus();
122124
}

addon/components/ivy-tabs-tablist.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ let instanceCount = 0;
2424
export default class IvyTabsTabListComponent extends Component {
2525
registerWithTabsContainer = modifier(() => {
2626
this.args.tabsContainer.registerTabList(this);
27-
// if none of the tabs are selected, try to select one
28-
let selected = this.tabs.find((tab) => tab.isSelected);
29-
if (!selected && this.tabs.length > 0) {
30-
this.selectTab();
31-
}
3227
return () => {
3328
this.args.tabsContainer.unregisterTabList(this);
3429
};
@@ -125,9 +120,14 @@ export default class IvyTabsTabListComponent extends Component {
125120
*/
126121
@action
127122
registerTab(tab) {
123+
this.tabs = this.tabs.concat(tab);
124+
// run this later so that all the tabs are registered before we try to select one
128125
runTask(this, () => {
129-
this.tabs = this.tabs.concat(tab);
130-
this.selectTab();
126+
// if none of the tabs are selected, try to select one
127+
let selected = this.tabs.find((tab) => tab.isSelected);
128+
if (!selected && this.tabs.length > 0) {
129+
this.selectTab();
130+
}
131131
});
132132
}
133133

@@ -208,8 +208,7 @@ export default class IvyTabsTabListComponent extends Component {
208208
@action
209209
selectTab() {
210210
const selection = this.selection;
211-
212-
if (isNone(selection) || this.tabs.length === 1) {
211+
if (isNone(selection)) {
213212
this.selectTabByIndex(0);
214213
} else {
215214
this.selectTabByModel(selection);
@@ -225,20 +224,18 @@ export default class IvyTabsTabListComponent extends Component {
225224
selectTabByIndex(index) {
226225
const tab = this.tabs[index];
227226

228-
if (tab && tab.isSelected === false) {
229-
runTask(tab, () => {
230-
tab.select();
231-
});
227+
if (tab) {
228+
tab.select();
232229
}
233230
}
234231

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

238235
if (tab) {
239-
runTask(tab, () => {
240-
tab.select();
241-
});
236+
tab.select();
237+
} else {
238+
this.selectTabByIndex(0);
242239
}
243240
}
244241

@@ -279,4 +276,8 @@ export default class IvyTabsTabListComponent extends Component {
279276
return element !== tab;
280277
});
281278
}
279+
280+
isRegistered(tab) {
281+
return this.tabs.includes(tab);
282+
}
282283
}

0 commit comments

Comments
 (0)