Skip to content

Commit f84de61

Browse files
committed
docs(material/tabs): add dynamically aligned tabs group example
adds an example for dynamically aligned tabs group closes #29029
1 parent ff3d342 commit f84de61

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

src/components-examples/material/tabs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {TabGroupAlignExample} from './tab-group-align/tab-group-align-example';
2+
export {TabGroupDynamicAlignExample} from './tab-group-dynamic-align/tab-group-dynamic-align-example';
23
export {TabGroupAnimationsExample} from './tab-group-animations/tab-group-animations-example';
34
export {TabGroupAsyncExample} from './tab-group-async/tab-group-async-example';
45
export {TabGroupBasicExample} from './tab-group-basic/tab-group-basic-example';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.example-action-button {
2+
margin-top: 8px;
3+
margin-bottom: 8px;
4+
margin-right: 8px;
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<button mat-raised-button class="example-action-button" (click)="alignment = 'start'">
2+
Start
3+
</button>
4+
5+
<button mat-raised-button class="example-action-button" (click)="alignment = 'center'">
6+
Center
7+
</button>
8+
9+
<button mat-raised-button class="example-action-button" (click)="alignment = 'end'">
10+
End
11+
</button>
12+
13+
<!-- #docregion dynamic-align-start -->
14+
<mat-tab-group mat-stretch-tabs="false" [mat-align-tabs]="alignment">
15+
<mat-tab label="First">Content 1</mat-tab>
16+
<mat-tab label="Second">Content 2</mat-tab>
17+
<mat-tab label="Third">Content 3</mat-tab>
18+
</mat-tab-group>
19+
<!-- #docregion dynamic-align-end -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Component} from '@angular/core';
2+
import {MatButtonModule} from '@angular/material/button';
3+
import {MatTabsModule} from '@angular/material/tabs';
4+
5+
/**
6+
* @title Tab group with dynamically aligned labels
7+
*/
8+
@Component({
9+
selector: 'tab-group-dynamic-align-example',
10+
templateUrl: 'tab-group-dynamic-align-example.html',
11+
styleUrl: 'tab-group-dynamic-align-example.css',
12+
standalone: true,
13+
imports: [MatTabsModule, MatButtonModule],
14+
})
15+
export class TabGroupDynamicAlignExample {
16+
alignment: 'start' | 'center' | 'end' = 'start';
17+
}

src/dev-app/tabs/tabs-demo.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<h3>Tab group alignment</h3>
22
<tab-group-align-example></tab-group-align-example>
3+
<h3>Tab group dynamic alignment</h3>
4+
<tab-group-dynamic-align-example></tab-group-dynamic-align-example>
35
<h3>Tab group animations</h3>
46
<tab-group-animations-example></tab-group-animations-example>
57
<h3>Tab group async</h3>
@@ -25,4 +27,4 @@ <h3>Inverted Tabs</h3>
2527
<h3>Ink bar fit to content</h3>
2628
<tab-group-ink-bar-example></tab-group-ink-bar-example>
2729
<h3>Tab group with the headers on the bottom</h3>
28-
<tab-group-header-below-example></tab-group-header-below-example>
30+
<tab-group-header-below-example></tab-group-header-below-example>

src/dev-app/tabs/tabs-demo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
TabGroupPaginatedExample,
2222
TabGroupStretchedExample,
2323
TabNavBarBasicExample,
24+
TabGroupDynamicAlignExample,
2425
} from '@angular/components-examples/material/tabs';
2526
import {ChangeDetectionStrategy, Component} from '@angular/core';
2627
import {MatTabsModule} from '@angular/material/tabs';
@@ -44,6 +45,7 @@ import {MatTabsModule} from '@angular/material/tabs';
4445
TabGroupBasicExample,
4546
TabGroupCustomLabelExample,
4647
TabGroupDynamicHeightExample,
48+
TabGroupDynamicAlignExample,
4749
MatTabsModule,
4850
],
4951
changeDetection: ChangeDetectionStrategy.OnPush,

src/material/tabs/tabs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ do so using the `[mat-align-tabs]` attribute.
7676
"file": "tab-group-align-example.html",
7777
"region": "align-start"}) -->
7878

79+
Alternatively you can also use `[mat-align-tabs]` input which takes either `start`, `center` or `end`.
80+
81+
<!-- example({"example": "tab-group-dynamic-align",
82+
"file": "tab-group-dynamic-align-example.html",
83+
"region": "dynamic-align-start"}) -->
84+
7985
### Controlling the tab animation
8086
You can control the duration of the tabs' animation using the `animationDuration` input. If you
8187
want to disable the animation completely, you can do so by setting the properties to `0ms`. The

0 commit comments

Comments
 (0)