Skip to content

Commit a72883f

Browse files
authored
refactor: update snippets/embedded example comments in material docs md to reflect new API (chips, menu, tabs) (#19486)
* mark regions and change docs for chips, menu and tabs * add space after colon in object literal Co-authored-by: Annie Wang <annieyw@google.com>
1 parent 9716a01 commit a72883f

File tree

12 files changed

+55
-133
lines changed

12 files changed

+55
-133
lines changed

src/components-examples/material/menu/menu-nested/menu-nested-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<button mat-button [matMenuTriggerFor]="animals">Animal index</button>
2-
2+
<!-- #docregion sub-menu -->
33
<mat-menu #animals="matMenu">
44
<button mat-menu-item [matMenuTriggerFor]="vertebrates">Vertebrates</button>
55
<button mat-menu-item [matMenuTriggerFor]="invertebrates">Invertebrates</button>
@@ -12,6 +12,7 @@
1212
<button mat-menu-item>Birds</button>
1313
<button mat-menu-item>Mammals</button>
1414
</mat-menu>
15+
<!-- #enddocregion sub-menu -->
1516

1617
<mat-menu #invertebrates="matMenu">
1718
<button mat-menu-item>Insects</button>

src/components-examples/material/menu/menu-overview/menu-overview-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<!-- #docregion mat-menu-trigger-for -->
12
<button mat-button [matMenuTriggerFor]="menu">Menu</button>
3+
<!-- #enddocregion mat-menu-trigger-for -->
24
<mat-menu #menu="matMenu">
35
<button mat-menu-item>Item 1</button>
46
<button mat-menu-item>Item 2</button>

src/components-examples/material/menu/menu-position/menu-position-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<button mat-button [matMenuTriggerFor]="aboveMenu">Above</button>
2+
<!-- #docregion menu-position -->
23
<mat-menu #aboveMenu="matMenu" yPosition="above">
4+
<!-- #enddocregion menu-position -->
35
<button mat-menu-item>Item 1</button>
46
<button mat-menu-item>Item 2</button>
57
</mat-menu>

src/components-examples/material/tabs/tab-group-align/tab-group-align-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<!-- #docregion align-start -->
12
<mat-tab-group mat-align-tabs="start">
3+
<!-- #enddocregion align-start -->
24
<mat-tab label="First">Content 1</mat-tab>
35
<mat-tab label="Second">Content 2</mat-tab>
46
<mat-tab label="Third">Content 3</mat-tab>

src/components-examples/material/tabs/tab-group-animations/tab-group-animations-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ <h3>No animation</h3>
77
</mat-tab-group>
88

99
<h3>Very slow animation</h3>
10+
<!-- #docregion slow-animation-duration -->
1011
<mat-tab-group animationDuration="2000ms">
12+
<!-- #enddocregion slow-animation-duration -->
1113
<mat-tab label="First">Content 1</mat-tab>
1214
<mat-tab label="Second">Content 2</mat-tab>
1315
<mat-tab label="Third">Content 3</mat-tab>

src/components-examples/material/tabs/tab-group-custom-label/tab-group-custom-label-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<mat-tab-group>
22
<mat-tab>
3+
<!-- #docregion label-directive -->
34
<ng-template mat-tab-label>
45
<mat-icon class="example-tab-icon">thumb_up</mat-icon>
56
First
67
</ng-template>
8+
<!-- #enddocregion label-directive -->
79
Content 1
810
</mat-tab>
911

src/components-examples/material/tabs/tab-group-dynamic-height/tab-group-dynamic-height-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<!-- #docregion dynamic-height -->
12
<mat-tab-group dynamicHeight>
3+
<!-- #enddocregion dynamic-height -->
24
<mat-tab label="Short tab">
35
<div class="example-small-box mat-elevation-z4">
46
Small content

src/components-examples/material/tabs/tab-group-lazy-loaded/tab-group-lazy-loaded-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<mat-tab-group>
2+
<!-- #docregion mat-tab-content -->
23
<mat-tab label="First">
34
<ng-template matTabContent>
45
Content 1 - Loaded: {{getTimeLoaded(1) | date:'medium'}}
56
</ng-template>
67
</mat-tab>
8+
<!-- #enddocregion mat-tab-content -->
79
<mat-tab label="Second">
810
<ng-template matTabContent>
911
Content 2 - Loaded: {{getTimeLoaded(2) | date:'medium'}}

src/components-examples/material/tabs/tab-nav-bar-basic/tab-nav-bar-basic-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
<!-- #docregion mat-tab-nav -->
12
<nav mat-tab-nav-bar [backgroundColor]="background">
23
<a mat-tab-link *ngFor="let link of links"
34
(click)="activeLink = link"
45
[active]="activeLink == link"> {{link}} </a>
56
<a mat-tab-link disabled>Disabled Link</a>
67
</nav>
8+
<!-- #enddocregion mat-tab-nav -->
79

810
<button mat-raised-button class="example-action-button" (click)="toggleBackground()">
911
Toggle background

src/material/chips/chips.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
`<mat-chip-list>` displays a list of values as individual, keyboard accessible, chips.
22

3-
<!-- example(chips-overview) -->
4-
5-
```html
6-
<mat-chip-list>
7-
<mat-chip>Papadum</mat-chip>
8-
<mat-chip>Naan</mat-chip>
9-
<mat-chip>Dal</mat-chip>
10-
</mat-chip-list>
11-
```
3+
<!-- example({"example": "chips-overview",
4+
"file": "chips-overview-example.html"}) -->
125

136
### Unstyled chips
147
By default, `<mat-chip>` has Material Design styles applied. For a chip with no styles applied,
@@ -59,13 +52,8 @@ also gain focus when clicked, ensuring keyboard navigation starts at the appropr
5952
If you want the chips in the list to be stacked vertically, instead of horizontally, you can apply
6053
the `mat-chip-list-stacked` class, as well as the `aria-orientation="vertical"` attribute:
6154

62-
```html
63-
<mat-chip-list class="mat-chip-list-stacked" aria-orientation="vertical">
64-
<mat-chip>Papadum</mat-chip>
65-
<mat-chip>Naan</mat-chip>
66-
<mat-chip>Dal</mat-chip>
67-
</mat-chip-list>
68-
```
55+
<!-- example({"example": "chips-stacked",
56+
"file": "chips-stacked-example.html"}) -->
6957

7058
### Specifying global configuration defaults
7159
Default options for the chips module can be specified using the `MAT_CHIPS_DEFAULT_OPTIONS`

src/material/menu/menu.md

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44

55
By itself, the `<mat-menu>` element does not render anything. The menu is attached to and opened
66
via application of the `matMenuTriggerFor` directive:
7-
```html
8-
<mat-menu #appMenu="matMenu">
9-
<button mat-menu-item>Settings</button>
10-
<button mat-menu-item>Help</button>
11-
</mat-menu>
12-
13-
<button mat-icon-button [matMenuTriggerFor]="appMenu">
14-
<mat-icon>more_vert</mat-icon>
15-
</button>
16-
```
7+
<!-- example({"example": "menu-overview",
8+
"file": "menu-overview-example.html",
9+
"region": "mat-menu-trigger-for"}) -->
1710

1811
### Toggling the menu programmatically
1912
The menu exposes an API to open/close programmatically. Please note that in this case, an
@@ -32,23 +25,8 @@ class MyComponent {
3225
### Icons
3326
Menus support displaying `mat-icon` elements before the menu item text.
3427

35-
*my-comp.html*
36-
```html
37-
<mat-menu #menu="matMenu">
38-
<button mat-menu-item>
39-
<mat-icon>dialpad</mat-icon>
40-
<span>Redial</span>
41-
</button>
42-
<button mat-menu-item disabled>
43-
<mat-icon>voicemail</mat-icon>
44-
<span>Check voicemail</span>
45-
</button>
46-
<button mat-menu-item>
47-
<mat-icon>notifications_off</mat-icon>
48-
<span>Disable alerts</span>
49-
</button>
50-
</mat-menu>
51-
```
28+
<!-- example({"example": "menu-icons",
29+
"file": "menu-icons-example.html"}) -->
5230

5331
### Customizing menu position
5432

@@ -57,43 +35,19 @@ its trigger. The position can be changed using the `xPosition` (`before | after`
5735
(`above | below`) attributes. The menu can be forced to overlap the trigger using the
5836
`overlapTrigger` attribute.
5937

60-
```html
61-
<mat-menu #appMenu="matMenu" yPosition="above">
62-
<button mat-menu-item>Settings</button>
63-
<button mat-menu-item>Help</button>
64-
</mat-menu>
65-
66-
<button mat-icon-button [matMenuTriggerFor]="appMenu">
67-
<mat-icon>more_vert</mat-icon>
68-
</button>
69-
```
70-
71-
<!-- example(menu-position) -->
38+
<!-- example({"example": "menu-position",
39+
"file": "menu-position-example.html",
40+
"region": "menu-position"}) -->
7241

7342
### Nested menu
7443

7544
Material supports the ability for an `mat-menu-item` to open a sub-menu. To do so, you have to define
7645
your root menu and sub-menus, in addition to setting the `[matMenuTriggerFor]` on the `mat-menu-item`
7746
that should trigger the sub-menu:
7847

79-
```html
80-
<mat-menu #rootMenu="matMenu">
81-
<button mat-menu-item [matMenuTriggerFor]="subMenu">Power</button>
82-
<button mat-menu-item>System settings</button>
83-
</mat-menu>
84-
85-
<mat-menu #subMenu="matMenu">
86-
<button mat-menu-item>Shut down</button>
87-
<button mat-menu-item>Restart</button>
88-
<button mat-menu-item>Hibernate</button>
89-
</mat-menu>
90-
91-
<button mat-icon-button [matMenuTriggerFor]="rootMenu">
92-
<mat-icon>more_vert</mat-icon>
93-
</button>
94-
```
95-
96-
<!-- example(menu-nested) -->
48+
<!-- example({"example": "menu-nested",
49+
"file": "menu-nested-example.html",
50+
"region": "sub-menu"}) -->
9751

9852
### Lazy rendering
9953
By default, the menu content will be initialized even when the panel is closed. To defer

src/material/tabs/tabs.md

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,32 @@ the header, usually through keyboard navigation.
1919

2020
If a tab's label is only text then the simple tab-group API can be used.
2121

22-
```html
23-
<mat-tab-group>
24-
<mat-tab label="One">
25-
<h1>Some tab content</h1>
26-
<p>...</p>
27-
</mat-tab>
28-
<mat-tab label="Two">
29-
<h1>Some more tab content</h1>
30-
<p>...</p>
31-
</mat-tab>
32-
</mat-tab-group>
33-
```
22+
<!-- example({"example": "tab-group-basic",
23+
"file": "tab-group-basic.html"}) -->
3424

3525
For more complex labels, add a template with the `mat-tab-label` directive inside the `mat-tab`.
3626

37-
```html
38-
<mat-tab-group>
39-
<mat-tab>
40-
<ng-template mat-tab-label>
41-
The <em>best</em> pasta
42-
</ng-template>
43-
<h1>Best pasta restaurants</h1>
44-
<p>...</p>
45-
</mat-tab>
46-
<mat-tab>
47-
<ng-template mat-tab-label>
48-
<mat-icon>thumb_down</mat-icon> The worst sushi
49-
</ng-template>
50-
<h1>Terrible sushi restaurants</h1>
51-
<p>...</p>
52-
</mat-tab>
53-
</mat-tab-group>
54-
```
27+
<!-- example({"example": "tab-group-custom-label",
28+
"file": "tab-group-custom-label-example.html",
29+
"region": "label-directive"}) -->
5530

5631
### Dynamic Height
5732

5833
By default, the tab group will not change its height to the height of the currently active tab. To
5934
change this, set the `dynamicHeight` input to true. The tab body will animate its height according
6035
to the height of the active tab.
36+
37+
<!-- example({"example": "tab-group-dynamic-height",
38+
"file": "tab-group-dynamic-height-example.html",
39+
"region": "dynamic-height"}) -->
6140

6241
### Tabs and navigation
6342
While `<mat-tab-group>` is used to switch between views within a single route, `<nav mat-tab-nav-bar>`
6443
provides a tab-like UI for navigating between routes.
65-
```html
66-
<nav mat-tab-nav-bar>
67-
<a mat-tab-link
68-
*ngFor="let link of navLinks"
69-
[routerLink]="link.path"
70-
routerLinkActive #rla="routerLinkActive"
71-
[active]="rla.isActive">
72-
{{link.label}}
73-
</a>
74-
</nav>
75-
76-
<router-outlet></router-outlet>
77-
```
44+
45+
<!-- example({"example": "tab-nav-bar-basic",
46+
"file": "tab-nav-bar-basic-example.html",
47+
"region": "mat-tab-nav"}) -->
7848

7949
The `tab-nav-bar` is not tied to any particular router; it works with normal `<a>` elements and uses
8050
the `active` property to determine which tab is currently active. The corresponding
@@ -93,33 +63,26 @@ to lazy load the tab's content.
9363
Tab contents can be lazy loaded by declaring the body in a `ng-template`
9464
with the `matTabContent` attribute.
9565

96-
```html
97-
<mat-tab-group>
98-
<mat-tab label="First">
99-
<ng-template matTabContent>
100-
The First Content
101-
</ng-template>
102-
</mat-tab>
103-
<mat-tab label="Second">
104-
<ng-template matTabContent>
105-
The Second Content
106-
</ng-template>
107-
</mat-tab>
108-
</mat-tab-group>
109-
```
66+
<!-- example({"example": "tab-group-lazy-loaded",
67+
"file": "tab-group-lazy-loaded-example.html",
68+
"region": "mat-tab-content"}) -->
11069

11170
### Label alignment
11271
If you want to align the tab labels in the center or towards the end of the container, you can
11372
do so using the `[mat-align-tabs]` attribute.
11473

115-
<!-- example(tab-group-align) -->
74+
<!-- example({"example": "tab-group-align",
75+
"file": "tab-group-align-example.html",
76+
"region": "align-start"}) -->
11677

11778
### Controlling the tab animation
11879
You can control the duration of the tabs' animation using the `animationDuration` input. If you
11980
want to disable the animation completely, you can do so by setting the properties to `0ms`. The
12081
duration can be configured globally using the `MAT_TABS_CONFIG` injection token.
12182

122-
<!-- example(tab-group-animations) -->
83+
<!-- example({"example": "tab-group-animations",
84+
"file": "tab-group-animations-example.html",
85+
"region": "slow-animation-duration"}) -->
12386

12487
### Accessibility
12588
`<mat-tab-group>` and `<mat-nav-tab-bar>` use different interaction patterns. The

0 commit comments

Comments
 (0)