Skip to content

Commit f41d0f7

Browse files
authored
refactor: update snippets/embedded example comments in material docs md to reflect new API (autocomplete, datepicker, and menu) (#19283)
* update autocomplete and datepicker snippet comments * minor structural changes to docs surrounding snippet examples * update to use regions
1 parent c601a66 commit f41d0f7

File tree

5 files changed

+31
-64
lines changed

5 files changed

+31
-64
lines changed

src/components-examples/material/autocomplete/autocomplete-optgroup/autocomplete-optgroup-example.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
formControlName="stateGroup"
77
required
88
[matAutocomplete]="autoGroup">
9+
<!-- #docregion mat-autocomplete -->
910
<mat-autocomplete #autoGroup="matAutocomplete">
1011
<mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter">
1112
<mat-option *ngFor="let name of group.names" [value]="name">
1213
{{name}}
1314
</mat-option>
1415
</mat-optgroup>
1516
</mat-autocomplete>
17+
<!-- #enddocregion mat-autocomplete -->
1618
</mat-form-field>
1719
</form>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<form class="example-form">
22
<mat-form-field class="example-full-width">
3+
<!-- #docregion input -->
34
<input type="text"
45
placeholder="Pick one"
56
aria-label="Number"
67
matInput
78
[formControl]="myControl"
89
[matAutocomplete]="auto">
10+
<!-- #enddocregion input -->
11+
<!-- #docregion mat-autocomplete -->
912
<mat-autocomplete #auto="matAutocomplete">
1013
<mat-option *ngFor="let option of options" [value]="option">
1114
{{option}}
1215
</mat-option>
1316
</mat-autocomplete>
17+
<!-- #enddocregion mat-autocomplete -->
1418
</mat-form-field>
1519
</form>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<mat-form-field>
22
<mat-label>Choose a date</mat-label>
3+
<!-- #docregion toggle -->
34
<input matInput [matDatepicker]="picker">
45
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
56
<mat-datepicker #picker></mat-datepicker>
7+
<!-- #enddocregion toggle -->
68
</mat-form-field>

src/material/autocomplete/autocomplete.md

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,31 @@ The autocomplete is a normal text input enhanced by a panel of suggested options
22

33
### Simple autocomplete
44

5-
Start by adding a regular `matInput` to your template. Let's assume you're using the `formControl`
6-
directive from `ReactiveFormsModule` to track the value of the input.
5+
Start by creating the autocomplete panel and the options displayed inside it. Each option should be
6+
defined by a `mat-option` tag. Set each option's value property to whatever you'd like the value
7+
of the text input to be when that option is selected.
8+
9+
<!-- example({"example":"autocomplete-simple",
10+
"file":"autocomplete-simple-example.html",
11+
"region":"mat-autocomplete"}) -->
12+
13+
Next, create the input and set the `matAutocomplete` input to refer to the template reference we assigned
14+
to the autocomplete. Let's assume you're using the `formControl` directive from `ReactiveFormsModule` to
15+
track the value of the input.
716

817
> Note: It is possible to use template-driven forms instead, if you prefer. We use reactive forms
918
in this example because it makes subscribing to changes in the input's value easy. For this
1019
example, be sure to import `ReactiveFormsModule` from `@angular/forms` into your `NgModule`.
1120
If you are unfamiliar with using reactive forms, you can read more about the subject in the
1221
[Angular documentation](https://angular.io/guide/reactive-forms).
1322

14-
*my-comp.html*
15-
```html
16-
<mat-form-field>
17-
<input type="text" matInput [formControl]="myControl">
18-
</mat-form-field>
19-
```
20-
21-
Next, create the autocomplete panel and the options displayed inside it. Each option should be
22-
defined by a `mat-option` tag. Set each option's value property to whatever you'd like the value
23-
of the text input to be upon that option's selection.
24-
25-
*my-comp.html*
26-
```html
27-
<mat-autocomplete>
28-
<mat-option *ngFor="let option of options" [value]="option">
29-
{{ option }}
30-
</mat-option>
31-
</mat-autocomplete>
32-
```
33-
3423
Now we'll need to link the text input to its panel. We can do this by exporting the autocomplete
3524
panel instance into a local template variable (here we called it "auto"), and binding that variable
3625
to the input's `matAutocomplete` property.
3726

38-
*my-comp.html*
39-
```html
40-
<mat-form-field>
41-
<input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto">
42-
</mat-form-field>
43-
44-
<mat-autocomplete #auto="matAutocomplete">
45-
<mat-option *ngFor="let option of options" [value]="option">{{option}}</mat-option>
46-
</mat-autocomplete>
47-
```
48-
49-
<!-- example(autocomplete-simple) -->
27+
<!-- example({"example":"autocomplete-simple",
28+
"file":"autocomplete-simple-example.html",
29+
"region":"input"}) -->
5030

5131
### Adding a custom filter
5232

@@ -127,18 +107,9 @@ autocomplete is attached to using the `matAutocompleteOrigin` directive together
127107

128108
### Option groups
129109
`mat-option` can be collected into groups using the `mat-optgroup` element:
130-
<!-- example(autocomplete-optgroup) -->
131-
132-
133-
```html
134-
<mat-autocomplete #auto="matAutocomplete">
135-
<mat-optgroup *ngFor="let group of filteredGroups | async" [label]="group.name">
136-
<mat-option *ngFor="let option of group.options" [value]="option">
137-
{{option.name}}
138-
</mat-option>
139-
</mat-optgroup>
140-
</mat-autocomplete>
141-
```
110+
<!-- example({"example":"autocomplete-optgroup",
111+
"file":"autocomplete-optgroup-example.html",
112+
"region":"mat-autocomplete"}) -->
142113

143114
### Accessibility
144115
The input for an autocomplete without text or labels should be given a meaningful label via

src/material/datepicker/datepicker.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,17 @@ the calendar. It is made up of several components and directives that work toget
88
A datepicker is composed of a text input and a calendar pop-up, connected via the `matDatepicker`
99
property on the text input.
1010

11-
```html
12-
<input [matDatepicker]="myDatepicker">
13-
<mat-datepicker #myDatepicker></mat-datepicker>
14-
```
11+
There is also an optional datepicker toggle button that gives the user an easy way to open the datepicker pop-up.
1512

16-
An optional datepicker toggle button is available. A toggle can be added to the example above:
17-
18-
```html
19-
<input [matDatepicker]="myDatepicker">
20-
<mat-datepicker-toggle [for]="myDatepicker"></mat-datepicker-toggle>
21-
<mat-datepicker #myDatepicker></mat-datepicker>
22-
```
13+
<!-- example({"example":"datepicker-overview",
14+
"file":"datepicker-overview-example.html",
15+
"region":"toggle"}) -->
2316

2417
This works exactly the same with an input that is part of an `<mat-form-field>` and the toggle
2518
can easily be used as a prefix or suffix on the Material input:
2619

27-
```html
28-
<mat-form-field>
29-
<input matInput [matDatepicker]="myDatepicker">
30-
<mat-datepicker-toggle matSuffix [for]="myDatepicker"></mat-datepicker-toggle>
31-
<mat-datepicker #myDatepicker></mat-datepicker>
32-
</mat-form-field>
33-
```
20+
<!-- example({"example":"datepicker-overview",
21+
"file":"datepicker-overview-example.html"}) -->
3422

3523
If you want to customize the icon that is rendered inside the `mat-datepicker-toggle`, you can do so
3624
by using the `matDatepickerToggleIcon` directive:

0 commit comments

Comments
 (0)