Skip to content

Commit f1325c9

Browse files
fix _getPreSelectedTabId bug
1 parent 8072636 commit f1325c9

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/utils/api/api.factory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ const _apiProps = {
110110
return result;
111111
},
112112
_getPreSelectedTabId: function () {
113-
const selectedTabHistory = this.activedTabsHistory;
113+
const selectedTabHistory = [...this.activedTabsHistory.tabsId];
114114
let tabID = '';
115-
while (!tabID && selectedTabHistory.tabsId.length) {
116-
const _tabID = selectedTabHistory.popLastTabID();
115+
while (!tabID && selectedTabHistory.length) {
116+
const _tabID = selectedTabHistory.pop();
117117
if (_tabID) {
118118
const _tabData = this.getTab(_tabID);
119119
if (_tabData && !_tabData.disable && this.isOpen(_tabID) && !this.isSelected(_tabID)) tabID = _tabID;
@@ -186,7 +186,7 @@ Helper.setNoneEnumProps(_apiProps, {
186186
openedTabIDs.length && this.trigger('onOpen', this.userProxy, openedTabIDs);
187187
closedTabIDs.length && this.trigger('onClose', this.userProxy, closedTabIDs);
188188
if (isSwitched) {
189-
if (this.activedTabsHistory.tabsId.indexOf(newState.selectedTabID) === -1) {
189+
if (newState.selectedTabID && this.activedTabsHistory.tabsId.indexOf(newState.selectedTabID) === -1) {
190190
this.trigger('onFirstSelect', this.userProxy, {
191191
currentSelectedTabId: newState.selectedTabID,
192192
previousSelectedTabId: oldState.selectedTabID,

src/utils/api/api.factory.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ describe('Api.prototype._subscribeSelectedTabsHistory : ', () => {
532532
});
533533
});
534534
describe('Api.prototype._getPreSelectedTabId : ', () => {
535-
test(`it calls activeTabsHistory.popLastTabID repeatedly until it returns a tabID
536-
which is opened, not selected and none disable`, () => {
535+
test(`it should find an item from activeTabsHistory.tabsId which is opened, not selected and none disable`, () => {
537536
const obj = new apiConstructor(getDeps, {
538537
options: {
539538
tabs: [{id: '1'}, {id: '2'}, {id: '3'}, {id: '4'}, {id: '5'}],
@@ -545,7 +544,6 @@ describe('Api.prototype._getPreSelectedTabId : ', () => {
545544
obj.setTab('3', {disable: true}).setTab('4', {disable: true});
546545
const tabID = obj._getPreSelectedTabId();
547546
expect(tabID).toBe('2');
548-
expect(obj.activedTabsHistory.tabsId).toEqual(['3']);
549547
});
550548
test('it should return an empty string if activedTabsHistory.tabsId is empty or does not contain any valid tabID', () => {
551549
obj.stateRef = {selectedTabID: 'tab1', openTabIDs: ['tab1', 'tab2']};

0 commit comments

Comments
 (0)