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
mdcButtonIconto the button, the label should be wrapped in anmdcButtonLabeldirective:<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
mdcChipTextshould 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
mdcFocusTrapdirective is not required anymore. AnmdcDialogwill automatically also have the focus trap directive attached. -
The
scrollableproperty frommdcDialogBodyis 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:
mdcDialogSurfacemust be wrapped inmdcDialogContainer.mdcDialogHeader+mdcDialogHeaderTitleis replaced bymdcDialogTitle.mdcDialogBodyis replaced bymdcDialogContent.mdcDialogFooteris replaced bymdcDialogActions.mdcDialogCancelshould be raplced bymdcDialogTrigger="close".mdcDialogAcceptshould be replaced bymdcDialogTrigger="accept".mdcDialogBackdropshould 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:
mdcDrawerContaineris not wrappingmdcDraweranymore, and its properties are moved tomdcDrawer(this only affectsdismissibleandmodaldrawers).mdcDrawerToolbarSpacerdoes not exist anymore.mdcDrawerHeaderContentis replaced bymdcDrawerTitle, andmdcDrawerSubtitle.- For modal drawers an
mdcDrawerScrimshould be added as a sibling element of themdcDrawer. - For
dismissibledrawers it is recommended to apply themdcDrawerAppContentdirective 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
extendedproperty 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
mdcDialogand modalmdcDrawerdirectives. So you should removemdcFocusTrapfrom elements with those directives. - The escape key does not untrap an
mdcFocusTrapanymore. Add your own handlers if untrapping on Escape key press is required. (Note thatmdcDialogandmdcDraweralready have their own handlers for the Escape key, so handling Escape is only needed if you are implementing a rawmdcFocusTrap). mdcFocusTrapdoes 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 thatmdcDialogandmdcDraweralready come with scrim elements.- Property
untrapOnOutsideClickis not supported anymore. Please add your own click handler to the scrim mentioned in the previous bullet. - Property
ignoreEscapeis 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.
mdcIconToggleis replaced bymdcIconButton. See above.
- No changes required
- The
activatedproperty was removed. Useselectedto enable either the activated, or the selected state. ThemdcListwill choose between the different selection modes (aria-current,aria-selected,aria-checked) depending onselectionModeand DOM-structure. - Not setting the
nonInteractiveproperty will now make the list fully interactive. Previously a list withoutnonInteractiveset 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
mdcListItemTextdirectives. 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
mdcListItemPrimarydirectives. 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
mdcMenuthrough anmdcMenuTriggerdirective. This takes care of following ARIA recommended practices for focusing the correct element, and maintaining properaria-*androleattributes on the interaction element, menu, and list. - The
canceloutput has been removed. For detecting if the menu was closed without any menu choice selection, try to useafterClosedin 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
boxandoutlinedproperty are gone. AnmdcSelectwill now display in theoutlinedvariant when themdcFloatingLabelis wrapped insidemdcNotchedOutlineandmdcNotchedOutlineNotchdirectives. 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
mdcSelectdoes not wrap a nativeselectinput element anymore, but usesmdcSelectMenuandmdcListfor 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
mdcSelectthe 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
mdcSelectthe 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
MdcSnackbarServicepropertystartAlignedproperty is replaced by a properyy with the nameleading. - The
MdcSnackbarServicepropertydismissesOnActionwas removed. Snackbars will always close when the action button is clicked. - The property
multilineofMdcSnackbarMessageis replaced by a property with the namestacked. - The property
actionOnBottomwas removed. Set thestackedproperty when the action button must be shown below the text instead of adjacent to the text. - The default value for the
timeoutproperty of anMdcSnackbarMessagewas changed from 2750ms to 5000ms. - The property (observer)
afterShowofMdcSnackbarRefwas replaced by propertyafterOpened. - The property (observer)
afterHideofMdcSnackbarRefwas 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 anmdcTabScrollerdirective inside themdcTabBar. (The oldmdcTabBarScroller*directives were optional, and were wrapping the tab bar instead of being wrapped by it). - The
mdcTabRouterdirective is now implied by having an element that has both anmdcTaband arouterLinkattribute. It is recommended to changemdcTabRoutertomdcTab(althoughmdcTabRouteris 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
boxandoutlinedproperty are gone. AnmdcTextFieldwill now display in theoutlinedvariant when themdcFloatingLabelis wrapped insidemdcNotchedOutlineandmdcNotchedOutlineNotchdirectives. 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. mdcTextFieldHelperTextmust now be wrapped inside anmdcTextFieldHelperLinedirective.- For an outlined
mdcTextFieldthe 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
mdcTextFieldthe 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>
mdcToolbarwas replaced bymdcTopAppBar. Please see https://material.src.zone/components/top-app-bar for instructions and examples on using themdcTopAppBardirective.
- All documented utility directives have remained unchanged.