The material-components-web dependency has been upgraded to version 5.1.0. This upgrade includes substantial changes to many of the material components DOM-structure, and their styling via Sass. The Sass theming structure has chenged to use the new Sass module structure via @use
instead of @import
. More information can be found at Material Components Web Theming, and in the documentation for our components at Blox Material Components.
The remainder of this upgrade guide focuses on the new DOM-structure, and on changes in properties and action handlers that are introduced by the new material-components-web.
- No changes required
- When adding a trailing
mdcButtonIcon
to the button, the label should be wrapped in anmdcButtonLabel
directive:<button mdcButton> <span mdcButtonLabel>Label</span> <i mdcButtonIcon class="material-icons">favorite</i> </button>
- No changes required
- No changes required
- Chip DOM structure has changed
- The
mdcChipText
should be wrapped inmdcChipCell
+mdcChipPrimaryAction
. Before:After:<div mdcChip> <i mdcChipIcon class="material-icons">wb_sunny</i> <div mdcChipText>Turn lights on</div> </div>
<div mdcChip> <i mdcChipIcon class="material-icons">wb_sunny</i> <span mdcChipCell> <span mdcChipPrimaryAction> <div mdcChipText>Turn lights on</div> </span> </span> </div>
- An (optional) trailing icon for input chips should be wrapped in an
mdcChipCell
. Before:After:<div mdcChip> <i mdcChipIcon class="material-icons">face</i> <div mdcChipText>Text</div> <i class="material-icons" mdcChipIcon>cancel</i> </div>
<div mdcChip> <i mdcChipIcon class="material-icons">face</i> <span mdcChipCell> <span mdcChipPrimaryAction> <div mdcChipText>Text</div> </span> </span> <span mdcChipCell> <i mdcChipIcon class="material-icons">cancel</i> </span> </div>
-
The
mdcFocusTrap
directive is not required anymore. AnmdcDialog
will automatically also have the focus trap directive attached. -
The
scrollable
property frommdcDialogBody
is dropped. Whether a dialog body must be scrollable is now automatically detected by the dialog based on the height of the dialog body. -
The DOM structure has changed:
mdcDialogSurface
must be wrapped inmdcDialogContainer
.mdcDialogHeader
+mdcDialogHeaderTitle
is replaced bymdcDialogTitle
.mdcDialogBody
is replaced bymdcDialogContent
.mdcDialogFooter
is replaced bymdcDialogActions
.mdcDialogCancel
should be raplced bymdcDialogTrigger="close"
.mdcDialogAccept
should be replaced bymdcDialogTrigger="accept"
.mdcDialogBackdrop
should be replaced bymdcDialogScrim
.
Before:
<aside mdcDialog mdcFocusTrap> <div mdcDialogSurface> <header mdcDialogHeader> <h2 mdcDialogHeaderTitle>Modal Dialog</h2> </header> <section mdcDialogBody scrollable>The dialog body</section> <footer mdcDialogFooter> <button mdcButton mdcDialogCancel>Decline</button> <button mdcButton mdcDialogAccept>Accept</button> </footer> </div> <div mdcDialogBackdrop></div> </aside>
After:
<aside mdcDialog> <div mdcDialogContainer> <div mdcDialogSurface> <h2 mdcDialogTitle>Modal Dialog</h2> <section mdcDialogContent>The dialog body</section> <footer mdcDialogActions> <button mdcButton mdcDialogTrigger="close">Decline</button> <button mdcButton mdcDialogTrigger="accept" mdcDialogDefault>Accept</button> </footer> </div> </div> <div mdcDialogScrim></div> </aside>
-
The drawer types are now named:
permanent
,dismissible
(waspersistent
), andmodal
(wastemporary
). -
The DOM structure has changed:
mdcDrawerContainer
is not wrappingmdcDrawer
anymore, and its properties are moved tomdcDrawer
(this only affectsdismissible
andmodal
drawers).mdcDrawerToolbarSpacer
does not exist anymore.mdcDrawerHeaderContent
is replaced bymdcDrawerTitle
, andmdcDrawerSubtitle
.- For modal drawers an
mdcDrawerScrim
should be added as a sibling element of themdcDrawer
. - For
dismissible
drawers it is recommended to apply themdcDrawerAppContent
directive to the sibling element next to the drawer so that open/close animations work correctly.
Before:
<aside [mdcDrawerContainer]="drawerType" [(open)]="open"> <nav mdcDrawer> <div mdcDrawerToolbarSpacer></div> <div mdcDrawerHeader> <div mdcDrawerHeaderContent>Header</div> </div> <div mdcDrawerContent mdcListGroup> ... </div> </nav> </aside> <div>page content</div>
After:
<aside [mdcDrawer]="drawerType" [(open)]="open"> <div mdcDrawerHeader> <h3 mdcDrawerTitle>Header</h3> <h6 mdcDrawerSubtitle>subtitle</h6> </div> <div mdcDrawerContent mdcListGroup> ... </div> </aside> <div mdcDrawerScrim *ngIf="drawerType === 'modal'"></div> <div [mdcDrawerAppContent]="drawerType === 'dismissible'">page content</div>
- No changes required
- The
extended
property is removed. A floating action button will automatically be extended when it contains anmdcFabLabel
. Before:After:<button mdcFab extended> <span mdcFabIcon class="material-icons">favorite</span> <span mdcFabLabel>Like</span> </button>
<button mdcFab> <span mdcFabIcon class="material-icons">favorite</span> <span mdcFabLabel>Like</span> </button>
- A focus trap is now automatically applied to
mdcDialog
and modalmdcDrawer
directives. So you should removemdcFocusTrap
from elements with those directives. - The escape key does not untrap an
mdcFocusTrap
anymore. Add your own handlers if untrapping on Escape key press is required. (Note thatmdcDialog
andmdcDrawer
already have their own handlers for the Escape key, so handling Escape is only needed if you are implementing a rawmdcFocusTrap
). mdcFocusTrap
does not block mouse interaction anymore. Add a scrim element to prevent mouse interactions outside the trap (for an example check out the demo at https://material.src.zone/components/focus-trap). Please note thatmdcDialog
andmdcDrawer
already come with scrim elements.- Property
untrapOnOutsideClick
is not supported anymore. Please add your own click handler to the scrim mentioned in the previous bullet. - Property
ignoreEscape
is not supported anymore. See the previous comments about handling the Escape key.
- No changes required for the non-toggling variant of
mdcIconButton
. - The DOM structure has changed for toggling
mdcIconButton
. The on/off icons are now child elements ofmdcIconButton
. Before:After:<button mdcIconButton class="material-icons" labelOn="Remove from favorites" labelOff="Add to favorites" iconOn="favorite" iconOff="favorite_border" [(on)]="favorite"></button>
<button mdcIconToggle labelOn="Remove from favorites" labelOff="Add to favorites" [(on)]="favorite"> <i mdcIcon="on" class="material-icons">favorite</i> <i mdcIcon class="material-icons">favorite_border</i> </button>
- See https://material.src.zone/components/icon-button for more examples, including samples for SVG icons, and samples for icon fonts that use classnames instead of ligatures.
mdcIconToggle
is replaced bymdcIconButton
. See above.
- No changes required
- The
activated
property was removed. Useselected
to enable either the activated, or the selected state. ThemdcList
will choose between the different selection modes (aria-current
,aria-selected
,aria-checked
) depending onselectionMode
and DOM-structure. - Not setting the
nonInteractive
property will now make the list fully interactive. Previously a list withoutnonInteractive
set would only have stylings applied, but mouse and keyboard actions were not handled. - The DOM-structure of single-line-lists has changed. The text of each item should now be wrapped in
mdcListItemText
directives. Before:After:<li mdcListItem>Wi-Fi</li>
<li mdcListItem> <span mdcListItemText>Wi-Fi</span> </li>
- The DOM structure of two-line-lists has changed. The primary text of a list item should now be wrapped in
mdcListItemPrimary
directives. Before:After:<li mdcListItem> <span mdcListItemText> Wi-Fi <span mdcListItemSecondaryText>Strong signal</span> </span> </li>
<li mdcListItem> <span mdcListItemText> <span mdcListItemPrimaryText>Wi-Fi</span> <span mdcListItemSecondaryText>Strong signal</span> </span> </li>
- It is recommended to open an
mdcMenu
through anmdcMenuTrigger
directive. This takes care of following ARIA recommended practices for focusing the correct element, and maintaining properaria-*
androle
attributes on the interaction element, menu, and list. - The
cancel
output has been removed. For detecting if the menu was closed without any menu choice selection, try to useafterClosed
in combination with listening forpick
. - The DOM-structure of menu items has changed. Before:
After:
<li mdcListItem value="reload">Reload</li>
<li mdcListItem value="reload"> <span mdcListItemText>Reload</span> </li>
- No changes required
- No changes required
- The
box
andoutlined
property are gone. AnmdcSelect
will now display in theoutlined
variant when themdcFloatingLabel
is wrapped insidemdcNotchedOutline
andmdcNotchedOutlineNotch
directives. Otherwise the boxed variant will be used. You can change the styling at runtime, by changing the DOM-structure, as demonstrated in the Select Component Guide. - The
mdcSelect
does not wrap a nativeselect
input element anymore, but usesmdcSelectMenu
andmdcList
for the list of choices. - There is no need anymore to include an empty disabled option value for representing the no choice state.
- For an outlined
mdcSelect
the changes are as follows. Before:After:<div mdcSelect outlined> <select mdcSelectControl [(ngModel)]="value" [disabled]="disabled"> <option value="" disabled selected></option> <option value="green">Green</option> <option value="orange">Orange</option> <option value="red">Red</option> </select> <label mdcFloatingLabel>Pick a Color</label> </div>
<div mdcSelect [(ngModel)]="value" [disabled]="disabled"> <div mdcSelectAnchor> <div mdcSelectText>{{value}}</div> <span mdcNotchedOutline> <span mdcNotchedOutlineNotch> <span mdcFloatingLabel>Pick a Color</span> </span> </span> </div> <div mdcSelectMenu> <ul mdcList> <li mdcListItem value="green">Green</li> <li mdcListItem value="orange">Orange</li> <li mdcListItem value="red">Red</li> </ul> </div> </div>
- For a boxed
mdcSelect
the changes are as follows. Before:After:<div mdcSelect box> <select mdcSelectControl [(ngModel)]="value" [disabled]="disabled"> <option value="" disabled selected></option> <option value="green">Green</option> <option value="orange">Orange</option> <option value="red">Red</option> </select> <label mdcFloatingLabel>Pick a Color</label> </div>
<div mdcSelect [(ngModel)]="value" [disabled]="disabled"> <div mdcSelectAnchor> <div mdcSelectText>{{value}}</div> <span mdcFloatingLabel>Pick a Color</span> </div> <div mdcSelectMenu> <ul mdcList> <li mdcListItem value="green">Green</li> <li mdcListItem value="orange">Orange</li> <li mdcListItem value="red">Red</li> </ul> </div> </div>
- No changes required
- The
MdcSnackbarService
propertystartAligned
property is replaced by a properyy with the nameleading
. - The
MdcSnackbarService
propertydismissesOnAction
was removed. Snackbars will always close when the action button is clicked. - The property
multiline
ofMdcSnackbarMessage
is replaced by a property with the namestacked
. - The property
actionOnBottom
was removed. Set thestacked
property when the action button must be shown below the text instead of adjacent to the text. - The default value for the
timeout
property of anMdcSnackbarMessage
was changed from 2750ms to 5000ms. - The property (observer)
afterShow
ofMdcSnackbarRef
was replaced by propertyafterOpened
. - The property (observer)
afterHide
ofMdcSnackbarRef
was replaced by propertyafterClosed
.
- The DOM-structure has changed. Before:
After:
<div mdcSwitch> <input mdcSwitchInput type="checkbox"/> </div>
<div mdcSwitch> <div mdcSwitchThumb> <input mdcSwitchInput type="checkbox"/> </div> </div>
- The old
mdcTab*
directives have been replaced by completely newmdcTab*
directives, based on a new material components web component. - For details about the new components please check the Tab Directives Guide.
- The
mdcTabBarScroller*
directives are removed. A scroller must now always be added by having anmdcTabScroller
directive inside themdcTabBar
. (The oldmdcTabBarScroller*
directives were optional, and were wrapping the tab bar instead of being wrapped by it). - The
mdcTabRouter
directive is now implied by having an element that has both anmdcTab
and arouterLink
attribute. It is recommended to changemdcTabRouter
tomdcTab
(althoughmdcTabRouter
is still supported for backward compatibility). - The most notable changes are documented with the following snippets. Before:
After:
<nav mdcTabBar> <a mdcTab tabindex="0">Tab 1</a> <a mdcTab tabindex="0">Tab 2</a> </nav>
<nav mdcTabBar> <div mdcTabScroller> <div mdcTabScrollerArea> <div mdcTabScrollerContent> <a mdcTab> <span mdcTabContent> <span mdcTabLabel>Tab 1</span> </span> <span mdcTabIndicator><span mdcTabIndicatorContent></span></span> </a> <a mdcTab> <span mdcTabContent> <span mdcTabLabel>Tab 2</span> </span> <span mdcTabIndicator><span mdcTabIndicatorContent></span></span> </a> </div> </div> </div> </nav>
- The
box
andoutlined
property are gone. AnmdcTextField
will now display in theoutlined
variant when themdcFloatingLabel
is wrapped insidemdcNotchedOutline
andmdcNotchedOutlineNotch
directives. Otherwise the boxed variant will be used. You can change the styling at runtime, by changing the DOM-structure, as demonstrated in the Text Field Component Guide. mdcTextFieldHelperText
must now be wrapped inside anmdcTextFieldHelperLine
directive.- For an outlined
mdcTextField
the changes are as follows. Before:After:<div mdcTextField outlined [helperText]="helpertxt"> <input mdcTextFieldInput type="text"/> <label mdcFloatingLabel>Input Label</label> </div> <p mdcTextFieldHelperText #helpertext="mdcHelperText">Help text</p>
<label mdcTextField [helperText]="helpertext"> <input mdcTextFieldInput type="text"/> <span mdcNotchedOutline> <span mdcNotchedOutlineNotch> <span mdcFloatingLabel>Input Label</span> </span> </span> </label> <div mdcTextFieldHelperLine> <p mdcTextFieldHelperText #helpertext="mdcHelperText">Help text</p> </div>
- For a boxed
mdcTextField
the changes are as follows. Before:After:<div mdcTextField boxed [helperText]="helpertxt"> <input mdcTextFieldInput type="text"/> <label mdcFloatingLabel>Input Label</label> </div> <p mdcTextFieldHelperText #helpertext="mdcHelperText">Help text</p>
<label mdcTextField [helperText]="helpertext"> <input mdcTextFieldInput type="text"/> <span mdcFloatingLabel>Input Label</span> </label> <div mdcTextFieldHelperLine> <p mdcTextFieldHelperText #helpertext="mdcHelperText">Help text</p> </div>
mdcToolbar
was replaced bymdcTopAppBar
. Please see https://material.src.zone/components/top-app-bar for instructions and examples on using themdcTopAppBar
directive.
- All documented utility directives have remained unchanged.