[Tabs] Fix "Eager Load Tabs" option (#4371)

* If eager load is checked, tabs are pre-fetched and kept alive.
* If eager load is not checked, tabs are not pre-fetched, and are not kept alive
This commit is contained in:
Jamie V 2021-10-28 19:09:44 -07:00 committed by GitHub
parent e59e4efdf0
commit 4e325fb165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -152,6 +152,10 @@ export default {
},
methods: {
addTabToLoaded(tab) {
if (!this.internalDomainObject.keep_alive) {
this.loadedTabs = {};
}
this.loadedTabs[tab.keyString] = true;
},
setCurrentTabByIndex(index) {

View File

@ -173,9 +173,34 @@ describe('the plugin', function () {
return Vue.nextTick();
});
afterEach(() => {
count = 0;
});
it ('renders a tab for each item', () => {
let tabEls = element.querySelectorAll('.js-tab');
expect(tabEls.length).toEqual(2);
});
describe('with domainObject.keep_alive set to', () => {
it ('true, will keep all views loaded, regardless of current tab view', () => {
let tabViewEls = element.querySelectorAll('.c-tabs-view__object');
expect(tabViewEls.length).toEqual(2);
});
it ('false, will only keep the current tab view loaded', async () => {
testViewObject.keep_alive = false;
await Vue.nextTick();
let tabViewEls = element.querySelectorAll('.c-tabs-view__object');
expect(tabViewEls.length).toEqual(1);
});
});
});
});