Skip to content

Commit d2fc2fd

Browse files
authored
Merge pull request #412 from youda97/tabs
feat(tabs): Tabs used as navigation
2 parents a93e3ad + 6d030db commit d2fc2fd

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/tabs/tab.component.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let nextId = 0;
6666
selector: "ibm-tab",
6767
template: `
6868
<div
69-
tabIndex="0"
69+
[tabindex]="tabIndex"
7070
role="tabpanel"
7171
*ngIf="shouldRender()"
7272
[ngStyle]="{'display': active ? null : 'none'}"
@@ -79,55 +79,48 @@ export class Tab implements OnInit {
7979
/**
8080
* Boolean value reflects if the `Tab` is using a custom template for the heading.
8181
* Default value is false.
82-
* @memberof Tab
8382
*/
8483
public headingIsTemplate = false;
8584

8685
/**
8786
* The `Tab`'s title to be displayed or custom temaplate for the `Tab` heading.
8887
* @type {(string | TemplateRef<any>)}
89-
* @memberof Tab
9088
*/
9189
@Input() heading: string | TemplateRef<any>;
9290
/**
9391
* Indicates whether the `Tab` is active/selected.
9492
* Determines whether it's `TabPanel` is rendered.
95-
* @memberof Tab
9693
*/
9794
@Input() active = false;
9895
/**
9996
* Indicates whether or not the `Tab` item is disabled.
100-
* @memberof Tab
10197
*/
10298
@Input() disabled = false;
99+
100+
@Input() tabIndex = 0;
103101
// do we need id's?
104102
/**
105103
* Sets the id of the `Tab`. Will be uniquely generated if not provided.
106-
* @memberof Tab
107104
*/
108105
@Input() id = `n-tab-${nextId++}`;
109106
/**
110107
* Set to true to have Tab items cached and not reloaded on tab switching.
111-
* @memberof Tab
112108
*/
113109
@Input() cacheActive = false;
114110
/**
115111
* Value 'selected' to be emitted after a new `Tab` is selected.
116112
* @type {EventEmitter<void>}
117-
* @memberof Tab
118113
*/
119114
@Output() selected: EventEmitter<void> = new EventEmitter<void>();
120115

121116
/**
122117
* Used to set the id property on the element.
123-
* @memberof Tab
124118
*/
125119
@HostBinding("attr.id") attrClass = this.id;
126120

127121
/**
128122
* Checks for custom heading template on initialization and updates the value
129123
* of the boolean 'headingIsTemplate'.
130-
* @memberof Tab
131124
*/
132125
ngOnInit() {
133126
if (this.heading instanceof TemplateRef) {
@@ -137,7 +130,6 @@ export class Tab implements OnInit {
137130

138131
/**
139132
* Emit the status of the `Tab`, specifically 'select' and 'selected' properties.
140-
* @memberof Tab
141133
*/
142134
doSelect() {
143135
this.selected.emit();
@@ -146,7 +138,6 @@ export class Tab implements OnInit {
146138
/**
147139
* Returns value indicating whether this `Tab` should be rendered in a `TabPanel`.
148140
* @returns boolean
149-
* @memberof Tab
150141
*/
151142
shouldRender() {
152143
return this.active || this.cacheActive;

src/tabs/tabs.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export class Tabs implements AfterContentInit {
7777
* Set to `true` to put tabs in a loading state.
7878
*/
7979
@Input() skeleton = false;
80+
/**
81+
* Set to `true` to have the tabIndex of the all tabpanels be -1.
82+
*/
83+
@Input() isNavigation = false;
8084

8185
/**
8286
* Maintains a `QueryList` of the `Tab` elements and updates if `Tab`s are added or removed.
@@ -98,6 +102,10 @@ export class Tabs implements AfterContentInit {
98102
if (this.tabHeaders) {
99103
this.tabHeaders.cacheActive = this.cacheActive;
100104
}
105+
106+
this.tabs.forEach(tab => {
107+
tab.tabIndex = this.isNavigation ? -1 : 0;
108+
});
101109
}
102110

103111
/**

src/tabs/tabs.stories.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ storiesOf("Tabs", module)
1616
.addDecorator(withKnobs)
1717
.add("Basic", () => ({
1818
template: `
19-
<ibm-tabs [followFocus]="followFocus">
19+
<ibm-tabs [followFocus]="followFocus" [isNavigation]="isNavigation">
2020
<ibm-tab heading="one">foo</ibm-tab>
2121
<ibm-tab heading="two">bar</ibm-tab>
2222
</ibm-tabs>
2323
`,
2424
props: {
25-
followFocus: boolean("followFocus", true)
25+
followFocus: boolean("followFocus", true),
26+
isNavigation: boolean("isNavigation", false)
2627
}
2728
}))
2829
.add("With template", () => ({
@@ -38,12 +39,16 @@ storiesOf("Tabs", module)
3839
</svg>
3940
</div>
4041
</ng-template>
41-
<ibm-tabs>
42+
<ibm-tabs [followFocus]="followFocus" [isNavigation]="isNavigation">
4243
<ibm-tab heading="one">foo</ibm-tab>
4344
<ibm-tab heading="two">bar</ibm-tab>
4445
<ibm-tab [heading]="customTab">foo</ibm-tab>
4546
</ibm-tabs>
46-
`
47+
`,
48+
props: {
49+
followFocus: boolean("followFocus", true),
50+
isNavigation: boolean("isNavigation", false)
51+
}
4752
}))
4853
.add("Skeleton", () => ({
4954
template: `

0 commit comments

Comments
 (0)