Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tabset): add lazyLoad property to nb-tab so that it loads co… #227

Merged
merged 1 commit into from
Feb 13, 2018
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
18 changes: 18 additions & 0 deletions docs/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -3723,6 +3723,24 @@
"required": null,
"name": "badgeText",
"shortDescription": "Badge text to display"
},
{
"kind": "input",
"platform": null,
"isStatic": false,
"type": "boolean",
"required": null,
"name": "active",
"shortDescription": "Specifies active tab"
},
{
"kind": "input",
"platform": null,
"isStatic": false,
"type": "boolean",
"required": null,
"name": "lazyLoad",
"shortDescription": "Lazy load content before tab selection"
}
],
"methods": [],
Expand Down
16 changes: 16 additions & 0 deletions e2e/tabset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ describe('nb-tabset', () => {
});
});

it('should lazy load tab content', () => {
expect(element(by.css('nb-tabset:nth-child(8) > nb-tab[tabTitle="Tab #1"] > span'))
.getText()).toEqual('Content #1');

expect(element(by.css('nb-tabset:nth-child(8) > nb-tab[tabTitle="Tab #2"]'))
.getText()).toEqual('');

const tab3 = element(by.css('nb-tabset:nth-child(8) > nb-tab[tabTitle="Tab #3"] > span'));
const tab3Text = 'Content #3';
expect(browser.executeScript('return arguments[0].innerHTML;', tab3)).toEqual(tab3Text);

const tab4 = element(by.css('nb-tabset:nth-child(8) > nb-tab[tabTitle="Tab #4"] > span'));
const tab4Text = 'Content #4';
expect(browser.executeScript('return arguments[0].innerHTML;', tab4)).toEqual(tab4Text);
});

describe('badge', () => {
const badgeText = '29';
const badgesConf = {
Expand Down
22 changes: 21 additions & 1 deletion src/app/tabset-test/tabset-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone

@Component({
selector: 'nb-tabset-test',
styles: [
`
nb-tabset {
margin-bottom: 40px;
}
`,
],
template: `
<nb-layout>
<nb-layout-column>
Expand Down Expand Up @@ -68,7 +75,6 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
<span>Content #3</span>
</nb-tab>
</nb-tabset>

<nb-tabset fullWidth>
<nb-tab tabTitle="Tab #1" badgeText="29">
<span>Content #1</span>
Expand Down Expand Up @@ -127,6 +133,20 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
<span>Content #5</span>
</nb-tab>
</nb-tabset>
<nb-tabset>
<nb-tab tabTitle="Tab #1">
<span>Content #1</span>
</nb-tab>
<nb-tab tabTitle="Tab #2">
<span>Content #2</span>
</nb-tab>
<nb-tab tabTitle="Tab #3" lazyLoad>
<span>Content #3</span>
</nb-tab>
<nb-tab tabTitle="Tab #4" lazyLoad>
<span>Content #4</span>
</nb-tab>
</nb-tabset>
</nb-layout-column>
</nb-layout>
`,
Expand Down
14 changes: 13 additions & 1 deletion src/framework/theme/components/tabset/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class NbTabComponent {
@HostBinding('class.content-active')
activeValue: boolean = false;

/**
* Specifies active tab
* @returns {boolean}
*/
@Input()
get active() {
return this.activeValue;
Expand All @@ -49,6 +53,15 @@ export class NbTabComponent {
}
}

/**
* Lazy load content before tab selection
* @param {boolean} val
*/
@Input()
set lazyLoad(val: boolean) {
this.init = convertToBoolProperty(val);
}

/**
* Badge text to display
* @type string
Expand All @@ -70,7 +83,6 @@ export class NbTabComponent {
*/
@Input() badgePosition: string;

// TODO: it makes sense to add 'lazyLoad' input to 'nb-tabset' component and make this functionality configurable
init: boolean = false;
}

Expand Down