Skip to content

Commit 3bb346b

Browse files
authored
docs: fix some gaps in the migration guide (#25775)
* docs: fix some gaps in the migration guide * fixup! docs: fix some gaps in the migration guide * fixup! docs: fix some gaps in the migration guide * fixup! docs: fix some gaps in the migration guide * fixup! docs: fix some gaps in the migration guide * fixup! docs: fix some gaps in the migration guide
1 parent a849765 commit 3bb346b

File tree

1 file changed

+96
-90
lines changed

1 file changed

+96
-90
lines changed

guides/v15-mdc-migration.md

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ After upgrading to v15, you can run the migration tool to switch from the legacy
100100
implementations to the new MDC-based ones.
101101

102102
```shell
103-
ng generate # TODO(wagnermaciel): Insert command here.
103+
ng generate @angular/material:mdc-migration
104104
```
105105

106106
This command updates your TypeScript, styles, and templates to the new implementations, updating as
@@ -109,12 +109,13 @@ much as it can automatically.
109109
#### Running a Partial Migration
110110

111111
Depending on the size and complexity of your application, you may want to migrate a single component
112-
(or small group of components) at a time, rather than all at once.
113-
TODO(wagnermaciel): Add details on this: script params, which components need to move together
112+
or small group of components at a time, rather than all components at once.
114113

115114
You may also want to migrate your app one module at a time instead of all together. You can use both
116115
the old implementation and new implementation in the same application, as long as they aren't used
117-
in the same `NgModule`. TODO(wagnermaciel): Add detail on this: script params.
116+
in the same `NgModule`.
117+
118+
The script will prompt you for the directory and components you want to migrate.
118119

119120
### 3. Check for TODOs left by the migration tool.
120121

@@ -123,12 +124,11 @@ attempt to add comments for a human to follow up. These TODO comments follow a c
123124
they can be easily identified.
124125

125126
```ts
126-
// TODO(wagnermaciel): Do we have a common format for all TODOs the script adds?
127+
// TODO(mdc-migration): ...
127128
```
128129

129-
To search for all comments left by the migration tool, search for `TODO(...):` in your IDE.
130-
131-
TODO(amysorto): Can we have the schematic generate a CSV of TODOs that can be imported into Jira
130+
To search for all comments left by the migration tool, search for `TODO(mdc-migration):` in your
131+
IDE.
132132

133133
### 4. Verify Your Application
134134

@@ -150,32 +150,16 @@ DOM and CSS of the components, you may need to tweak some of your application's
150150
* Component size, color, spacing, shadows, and animations all change slightly across the board.
151151
These changes generally improve spec-compliance and accessibility.
152152

153-
* CSS classes applied to components use the `mat-mdc` prefix, whereas before it was simply a `mat`
153+
* The DOM structure of components has changed to allow for improved accessibility and compliance
154+
with the Material Design spec.
155+
156+
* CSS classes applied to components use the `mat-mdc-` prefix, whereas before it was simply a `mat-`
154157
prefix. Elements that roughly correspond to element in the old implementation have been given the
155158
same class name (aside from the prefix). For example, the button’s host class is `mat-mdc-button`
156159
instead of `mat-button`. However, not all elements in the previous implementation have an
157160
equivalent element in the new implementation.
158161

159-
### Core Styles & Theming
160-
161-
* `mat.core()` no longer includes component typography styles. If your application was relying on
162-
this, you may need to add typography styles explicitly now. This can be done all at once:
163-
164-
```scss
165-
@import '@angular/material' as mat;
166-
167-
@include mat.all-component-typographies();
168-
```
169-
170-
or individually for components your application uses:
171-
172-
```scss
173-
@import '@angular/material' as mat;
174-
175-
@include mat.button-typography();
176-
@include mat.card-typography();
177-
// ...
178-
```
162+
### Theming
179163

180164
* Default typography levels defined by `mat.define-typography-config` have been updated to reflect
181165
changes to the Material Design spec.
@@ -195,6 +179,7 @@ DOM and CSS of the components, you may need to tweak some of your application's
195179
```
196180

197181
If you prefer a different default density level, you can set it in your theme config:
182+
<!-- TODO(wagnermaciel): link to density docs for more info once they exist. -->
198183

199184
```scss
200185
$theme: mat.define-light-theme((
@@ -203,8 +188,6 @@ DOM and CSS of the components, you may need to tweak some of your application's
203188
));
204189
```
205190

206-
TODO(mmalerba): link to density docs once they exist.
207-
208191
### Autocomplete
209192

210193
* Long options now wrap instead of truncating.
@@ -254,31 +237,49 @@ TODO(mmalerba): link to density docs once they exist.
254237

255238
* `<mat-card-content>` no longer sets any typography styles, users are free to add whatever
256239
typography styles make sense for their application, either to `<mat-card-content>` itself or any
257-
child elements as appropriate.
240+
child elements as appropriate. For example:
241+
242+
```scss
243+
@use '@angular/material' as mat;
244+
@include mat.typography-hierarchy();
245+
```
246+
247+
```html
248+
<mat-card>
249+
<mat-card-content class="mat-body-1">...</mat-card-content>
250+
</mat-card>
251+
```
258252

259253
### Checkbox
260254

261255
* Clicks on the checkbox now trigger directly on the native checkbox element rather than a shim div.
262256
Native checkboxes have bizarre behavior when calling `preventDefault` on their `click` event, so
263257
users should not call `preventDefault` on `click`.
264258

265-
* Accessibility: Checkbox touch targets are larger, now 40px instead of 16px, which is more
266-
accessible.
259+
* Checkbox touch targets are larger, now 40px instead of 16px, which is more accessible. Be sure to
260+
allow enough space in your layout so that the touch target does not overlap other components. If
261+
you are not concerned with accessibility you can match the previous size by using density -5 for
262+
the checkbox.
263+
264+
```scss
265+
@use '@angular/material' as mat;
266+
@include mat.checkbox-density(-5px);
267+
```
267268

268269
* Checkbox color may be changed to white or black due to a change in heuristics based on the
269270
application’s theme. Previously, the check’s color would be set to the theme’s background color.
270271
With MDC, it is determined by whether white or black has the most contrast against the primary
271272
color.
272273

273-
* Accessibility: Focus state is slightly darker, improving contrast ratio
274-
275-
* Many checkboxes on the page may cause the animation to seem slow
274+
* Focus state is slightly darker, improving contrast ratio.
276275

277-
* Text styles will not be inherited; you will need to specifically target the checkbox’s `label`.
276+
* Text styles will not be inherited; you will need to specifically target the checkbox’s `label` to
277+
override typography properties.
278278

279279
* After toggling a checkbox with the mouse, the ripple will remain visible instead of animating out.
280280

281281
### Chips
282+
<!-- TODO(zarend): review -->
282283

283284
* The chips component has been split into multiple variants corresponding with more appropriate
284285
interaction patterns for accessibility. The original `mat-chip-list` used `role="listbox"`, but
@@ -304,7 +305,7 @@ TODO(mmalerba): link to density docs once they exist.
304305

305306
* The `.mat-dialog-container` does not contain a 24px padding anymore. Instead, the inner dialog
306307
directives are responsible for adding the right padding. This will be apparent if your dialog does
307-
not use any of the directives like `mat-dialog-content`.
308+
not use any of the directives like `<mat-dialog-content>`.
308309

309310
* `mat-dialog-content` uses the font-settings specified by the Material Design spec, which includes
310311
a rather roomy line-height. If you have an information-dense dialog that doesn't look good with
@@ -344,6 +345,9 @@ TODO(mmalerba): link to density docs once they exist.
344345
behaved like a placeholder. If you need this behavior, use the `placeholder` property on `<input>`
345346
instead.
346347

348+
* Custom form field controls may need their styles adjusted to account for the fact that the
349+
surrounding form field DOM and styles have changed.
350+
347351
### Input
348352

349353
* MatInput must be inside `<mat-form-field>`. Previously it was (unintentionally) possible to use an
@@ -353,11 +357,11 @@ TODO(mmalerba): link to density docs once they exist.
353357
`<input matInput type="date">`, if you want this indicator to appear for your inputs, use the
354358
following styles:
355359

356-
```scss
357-
.mat-mdc-input-element::-webkit-calendar-picker-indicator {
358-
display: block;
359-
}
360-
```
360+
```scss
361+
.mat-mdc-input-element::-webkit-calendar-picker-indicator {
362+
display: block;
363+
}
364+
```
361365

362366
### List
363367

@@ -381,9 +385,9 @@ TODO(mmalerba): link to density docs once they exist.
381385
</mat-list-item>
382386
```
383387

384-
* The amount of lines is automatically inferred. e.g. in the snippet above the list item will
385-
acquire space for two lines. With the new API you can now set an explicit number of lines on the
386-
`<mat-list-item>` to activate wrapping.
388+
* The amount of lines is automatically inferred. For example, in the snippet above the list item
389+
will acquire space for two lines. With the new API you can now set an explicit number of lines on
390+
the `<mat-list-item>` to activate wrapping.
387391

388392
```html
389393
<mat-list-item lines="3">
@@ -420,7 +424,7 @@ TODO(mmalerba): link to density docs once they exist.
420424
`<mat-icon>` use `ngProjectAs="mat-icon"` to project it into the icon slot.
421425

422426
* If you need your icon to appear at the end of the item (not officially supported by the spec)
423-
you can wrap both the text and your icon in a span, e.g.
427+
you can wrap both the text and your icon in a span, for example:
424428

425429
```html
426430
<span>
@@ -439,6 +443,8 @@ TODO(mmalerba): link to density docs once they exist.
439443

440444
* Long options now wrap instead of truncating with an ellipsis.
441445

446+
* Option heights are no longer capped at `48px`.
447+
442448
### Paginator
443449

444450
* The form-field inside of `mat-paginator` only supports the `appearance` options offered by the new
@@ -464,16 +470,14 @@ TODO(mmalerba): link to density docs once they exist.
464470

465471
* Labels are smaller and further away from the radio button to align with the Material Design spec.
466472

467-
* Accessibility: The touch target is much larger than the radio button; to match the legacy size,
468-
you can provide a `-5` density to the radio button's theme mixin:
469-
470-
```scss
471-
@use '@angular/material' as mat;
473+
* The touch target is now much larger and more accessible. Be sure to allow enough space in your
474+
layout so that the touch target does not overlap other components. If you are not concerned with
475+
accessibility you can match the previous size by using density -5 for the radio.
472476

473-
@include mat.radio-theme(
474-
map-merge($theme, (density: -5))
475-
);
476-
```
477+
```scss
478+
@use '@angular/material' as mat;
479+
@include mat.radio-density(-5px);
480+
```
477481

478482
### Select
479483

@@ -491,47 +495,46 @@ TODO(mmalerba): link to density docs once they exist.
491495
is the same width as the form-field
492496

493497
### Slide Toggle
498+
<!-- TODO(zarend): review -->
494499

495-
* Accessibility: MDC-based version uses `<button role="switch">` to represent the toggle rather than
496-
`<input type="checkbox">`
500+
* To improve accessibility, the MDC-based version uses `<button role="switch">` to represent the
501+
toggle rather than `<input type="checkbox">`.
497502

498-
* Accessibility: The touch target is much larger than the slide toggle; to match the legacy size,
499-
you can provide a `-5` density to the slide toggle’s theme mixin:
503+
* The touch target is much larger and more accessible. Be sure to allow enough space in your
504+
layout so that the touch target does not overlap other components. If you are not concerned with
505+
accessibility you can match the previous size by using density -5 for the slide-toggle.
500506

501507
```scss
502508
@use '@angular/material' as mat;
503-
504-
@include mat.slide-toggle-theme(
505-
map-merge($theme, (density: -5))
506-
);
509+
@include mat.slide-toggle-density(-5px);
507510
```
508511

509512
* The label is closer to the enabled toggle
510513

511514
### Slider
515+
<!-- TODO(wagnermaciel): review -->
512516

513-
* Accessibility: sliders now work with mobile device screen readers.
517+
* Sliders now work with mobile device screen readers.
514518

515519
* To accommodate range sliders, the implementation has changed from the `<mat-slider>` element being
516520
the form control to the `<mat-slider>` element containing 1-2 `<input>` elements (the slider
517521
"thumbs") that act as the form control(s). The value, associated events (`input`, `change`), and
518522
labels (`aria-label`) now live on the `<input>` elements instead.
519523

520524
* Vertical sliders and inverted sliders are no longer supported, as they are no longer part of the
521-
Material Design spec. TODO(jelbourn): should we add a note that vertical sliders are likely to
522-
return in a future version?
525+
Material Design spec.
523526

524-
* Range sliders are now supported. TODO(wagnermaciel): add more about this.
527+
* Range sliders are now supported. <!-- TODO(wagnermaciel): add more about this. -->
525528

526529
### Snack Bar
527530

528531
* For simple, text-based snack-bars, there are no significant changes.
529532

530533
* For simple snack-bars with an action button, they use the MDC-based mat-button, so your
531-
application will need to include the Sass theming mixin for the MDC-based button
534+
application will need to include the Sass theming mixin for the MDC-based button.
532535

533-
* For snack-bars that use custom structured content (i.e. calls to `MatSnackBar.openFromComponent`
534-
and `MatSnackBar.openFromTemplate`), you should use the following new directives to annotate your
536+
* For snack-bars that use custom structured content (if you call `MatSnackBar.openFromComponent` or
537+
`MatSnackBar.openFromTemplate`), you should use the following new directives to annotate your
535538
content:
536539
* `matSnackBarLabel` to mark the text displayed to users
537540
* `matSnackBarActions` to mark the element containing the action buttons
@@ -545,22 +548,25 @@ TODO(mmalerba): link to density docs once they exist.
545548

546549
### Table
547550

548-
* All cells have a `16px` left and right padding instead of just the leftmost and rightmost cells having a padding of `24px`.
551+
* All cells have a `16px` left and right padding instead of just the leftmost and rightmost cells
552+
having a padding of `24px`.
549553

550-
* Header cells have the same color and text size as the data rows instead of having more grayish and smaller text.
554+
* Header cells have the same color and text size as the data rows instead of having more grayish and
555+
smaller text.
551556

552-
* Cell text no longer wraps by default. Cell wrapping can be enabled by applying `white-space: normal` to
553-
the table cells.
557+
* Cell text no longer wraps by default. Cell wrapping can be enabled by applying
558+
`white-space: normal` to the table cells.
554559

555560
* Row height is `52px` instead of `48px`.
556561

557562
* Cell box-sizing is `border-box` instead of `content-box`. This may affect custom width styles.
558563

559-
* The table's last row does not include a bottom border row because the table is expected to have a border.
564+
* The table's last row does not include a bottom border row because the table is expected to have a
565+
border.
560566

561-
* The paginator property of the `MatTableDataSource` has a generic interface that matches most of
562-
the paginator API. You may need to explicitly type the paginator to access the full API, e.g.
563-
`new MatTableDataSource<MyData, MatPaginator>();`
567+
* The paginator property of the `MatTableDataSource` has a generic interface that matches most, but
568+
not all of the paginator API. You may need to explicitly type the paginator to access the full
569+
API, for example: `new MatTableDataSource<MyData, MatPaginator>();`
564570

565571
* Flex tables (`<mat-table>`) display a border on the cells instead of rows.
566572

@@ -573,18 +579,18 @@ TODO(mmalerba): link to density docs once they exist.
573579
* Header labels stretch to fill the container's width. This can be turned off by
574580
setting the `<mat-tab-group>` input `mat-stretch-tabs` to `false`.
575581

576-
* The `<mat-tab-nav-bar>` requires a reference to a `<mat-tab-nav-panel>` using the `tabPanel` input.
577-
The `<mat-tab-nav-panel>` must wrap the content connected to the nav-bar. This allows
578-
the component to provide correct labeling for assistive technology.
582+
* The `<mat-tab-nav-bar>` requires a reference to a `<mat-tab-nav-panel>` using the `tabPanel`
583+
input. The `<mat-tab-nav-panel>` must wrap the content connected to the nav-bar. This allows the
584+
component to provide correct labeling for assistive technology.
579585

580-
```html
581-
<!-- Before -->
582-
<mat-tab-nav-bar>...</mat-tab-nav-bar>
586+
```html
587+
<!-- Before -->
588+
<mat-tab-nav-bar>...</mat-tab-nav-bar>
583589

584-
<!-- After -->
585-
<mat-tab-nav-bar [tabPanel]="tabPanel">...</mat-tab-nav-bar>
586-
<mat-tab-nav-panel #tabPanel>...</mat-tab-nav-panel>
587-
```
590+
<!-- After -->
591+
<mat-tab-nav-bar [tabPanel]="tabPanel">...</mat-tab-nav-bar>
592+
<mat-tab-nav-panel #tabPanel>...</mat-tab-nav-panel>
593+
```
588594

589595
### Tooltip
590596

0 commit comments

Comments
 (0)