Skip to content

Commit 1a6f924

Browse files
refactor(multiple): Updated components to use host binding for ngSkipHydration (angular#26763)
This adds the skip hydration host binding to every component where direct dom manipulation occurs that would break hydration. This allows anyone that uses material components to not have to worry about manually adding this attribute themselves.
1 parent ead1f98 commit 1a6f924

File tree

18 files changed

+25
-1
lines changed

18 files changed

+25
-1
lines changed

src/cdk/table/table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export interface RenderRow<T> {
205205
host: {
206206
'class': 'cdk-table',
207207
'[class.cdk-table-fixed-layout]': 'fixedLayout',
208+
'ngSkipHydration': 'true',
208209
},
209210
encapsulation: ViewEncapsulation.None,
210211
// The "OnPush" status for the `MatTable` component is effectively a noop, so we are removing it.

src/material/autocomplete/autocomplete.ts

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ export abstract class _MatAutocompleteBase
330330
inputs: ['disableRipple'],
331331
host: {
332332
'class': 'mat-mdc-autocomplete',
333+
'ngSkipHydration': 'true',
333334
},
334335
providers: [{provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatAutocomplete}],
335336
animations: [panelAnimation],

src/material/chips/chip-listbox.ts

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const MAT_CHIP_LISTBOX_CONTROL_VALUE_ACCESSOR: any = {
7575
'[attr.aria-disabled]': 'disabled.toString()',
7676
'[attr.aria-multiselectable]': 'multiple',
7777
'[attr.aria-orientation]': 'ariaOrientation',
78+
'ngSkipHydration': 'true',
7879
'[class.mat-mdc-chip-list-disabled]': 'disabled',
7980
'[class.mat-mdc-chip-list-required]': 'required',
8081
'(focus)': 'focus()',

src/material/legacy-autocomplete/autocomplete.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {_MatAutocompleteBase} from '@angular/material/autocomplete';
3535
inputs: ['disableRipple'],
3636
host: {
3737
'class': 'mat-autocomplete',
38+
'ngSkipHydration': 'true',
3839
},
3940
providers: [{provide: MAT_LEGACY_OPTION_PARENT_COMPONENT, useExisting: MatLegacyAutocomplete}],
4041
})

src/material/legacy-chips/chip-list.ts

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class MatLegacyChipListChange {
109109
'(blur)': '_blur()',
110110
'(keydown)': '_keydown($event)',
111111
'[id]': '_uid',
112+
'ngSkipHydration': 'true',
112113
},
113114
providers: [{provide: MatLegacyFormFieldControl, useExisting: MatLegacyChipList}],
114115
styleUrls: ['chips.css'],

src/material/legacy-form-field/form-field.ts

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export const MAT_LEGACY_FORM_FIELD_DEFAULT_OPTIONS =
153153
'[class.ng-invalid]': '_shouldForward("invalid")',
154154
'[class.ng-pending]': '_shouldForward("pending")',
155155
'[class._mat-animation-noopable]': '!_animationsEnabled',
156+
'ngSkipHydration': 'true',
156157
},
157158
inputs: ['color'],
158159
encapsulation: ViewEncapsulation.None,

src/material/legacy-menu/menu.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
'[attr.aria-label]': 'null',
4040
'[attr.aria-labelledby]': 'null',
4141
'[attr.aria-describedby]': 'null',
42+
'ngSkipHydration': 'true',
4243
},
4344
animations: [matMenuAnimations.transformMenu, matMenuAnimations.fadeInItems],
4445
providers: [{provide: MAT_MENU_PANEL, useExisting: MatLegacyMenu}],

src/material/legacy-select/select.ts

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class MatLegacySelectTrigger {}
149149
'(keydown)': '_handleKeydown($event)',
150150
'(focus)': '_onFocus()',
151151
'(blur)': '_onBlur()',
152+
'ngSkipHydration': 'true',
152153
},
153154
animations: [
154155
matLegacySelectAnimations.transformPanelWrap,

src/material/legacy-table/table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class MatLegacyRecycleRows {}
4646
host: {
4747
'class': 'mat-table',
4848
'[class.mat-table-fixed-layout]': 'fixedLayout',
49+
'ngSkipHydration': 'true',
4950
},
5051
providers: [
5152
// TODO(michaeljamesparsons) Abstract the view repeater strategy to a directive API so this code

src/material/legacy-tabs/tab-group.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
'class': 'mat-tab-group',
5555
'[class.mat-tab-group-dynamic-height]': 'dynamicHeight',
5656
'[class.mat-tab-group-inverted-header]': 'headerPosition === "below"',
57+
'ngSkipHydration': 'true',
5758
},
5859
})
5960
export class MatLegacyTabGroup extends _MatTabGroupBase {

src/material/menu/menu.ts

+1
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ export class _MatMenuBase
544544
'[attr.aria-label]': 'null',
545545
'[attr.aria-labelledby]': 'null',
546546
'[attr.aria-describedby]': 'null',
547+
'ngSkipHydration': 'true',
547548
},
548549
animations: [matMenuAnimations.transformMenu, matMenuAnimations.fadeInItems],
549550
providers: [{provide: MAT_MENU_PANEL, useExisting: MatMenu}],

src/material/select/select.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ export class MatSelectTrigger {}
11711171
'[attr.aria-disabled]': 'disabled.toString()',
11721172
'[attr.aria-invalid]': 'errorState',
11731173
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()',
1174+
'ngSkipHydration': 'true',
11741175
'[class.mat-mdc-select-disabled]': 'disabled',
11751176
'[class.mat-mdc-select-invalid]': 'errorState',
11761177
'[class.mat-mdc-select-required]': 'required',

src/material/sidenav/drawer.ts

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
101101
'class': 'mat-drawer-content',
102102
'[style.margin-left.px]': '_container._contentMargins.left',
103103
'[style.margin-right.px]': '_container._contentMargins.right',
104+
'ngSkipHydration': 'true',
104105
},
105106
changeDetection: ChangeDetectionStrategy.OnPush,
106107
encapsulation: ViewEncapsulation.None,
@@ -150,6 +151,7 @@ export class MatDrawerContent extends CdkScrollable implements AfterContentInit
150151
'[@transform]': '_animationState',
151152
'(@transform.start)': '_animationStarted.next($event)',
152153
'(@transform.done)': '_animationEnd.next($event)',
154+
'ngSkipHydration': 'true',
153155
},
154156
changeDetection: ChangeDetectionStrategy.OnPush,
155157
encapsulation: ViewEncapsulation.None,
@@ -635,6 +637,7 @@ export class MatDrawer implements AfterViewInit, AfterContentChecked, OnDestroy
635637
host: {
636638
'class': 'mat-drawer-container',
637639
'[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride',
640+
'ngSkipHydration': 'true',
638641
},
639642
changeDetection: ChangeDetectionStrategy.OnPush,
640643
encapsulation: ViewEncapsulation.None,

src/material/sidenav/sidenav.ts

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {ScrollDispatcher, CdkScrollable} from '@angular/cdk/scrolling';
3737
'class': 'mat-drawer-content mat-sidenav-content',
3838
'[style.margin-left.px]': '_container._contentMargins.left',
3939
'[style.margin-right.px]': '_container._contentMargins.right',
40+
'ngSkipHydration': 'true',
4041
},
4142
changeDetection: ChangeDetectionStrategy.OnPush,
4243
encapsulation: ViewEncapsulation.None,
@@ -77,6 +78,7 @@ export class MatSidenavContent extends MatDrawerContent {
7778
'[class.mat-sidenav-fixed]': 'fixedInViewport',
7879
'[style.top.px]': 'fixedInViewport ? fixedTopGap : null',
7980
'[style.bottom.px]': 'fixedInViewport ? fixedBottomGap : null',
81+
'ngSkipHydration': 'true',
8082
},
8183
changeDetection: ChangeDetectionStrategy.OnPush,
8284
encapsulation: ViewEncapsulation.None,
@@ -127,6 +129,7 @@ export class MatSidenav extends MatDrawer {
127129
host: {
128130
'class': 'mat-drawer-container mat-sidenav-container',
129131
'[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride',
132+
'ngSkipHydration': 'true',
130133
},
131134
changeDetection: ChangeDetectionStrategy.OnPush,
132135
encapsulation: ViewEncapsulation.None,

src/material/sort/sort.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ const _MatSortBase = mixinInitialized(mixinDisabled(class {}));
7373
@Directive({
7474
selector: '[matSort]',
7575
exportAs: 'matSort',
76-
host: {'class': 'mat-sort'},
76+
host: {
77+
'class': 'mat-sort',
78+
'ngSkipHydration': 'true',
79+
},
7780
inputs: ['disabled: matSortDisabled'],
7881
})
7982
export class MatSort

src/material/stepper/stepper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
138138
'[class.mat-stepper-header-position-bottom]': 'headerPosition === "bottom"',
139139
'[attr.aria-orientation]': 'orientation',
140140
'role': 'tablist',
141+
'ngSkipHydration': 'true',
141142
},
142143
animations: [
143144
matStepperAnimations.horizontalStepTransition,

src/material/table/table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class MatRecycleRows {}
4545
host: {
4646
'class': 'mat-mdc-table mdc-data-table__table',
4747
'[class.mdc-table-fixed-layout]': 'fixedLayout',
48+
'ngSkipHydration': 'true',
4849
},
4950
providers: [
5051
{provide: CdkTable, useExisting: MatTable},

src/material/tabs/tab-group.ts

+1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ export abstract class _MatTabGroupBase
523523
},
524524
],
525525
host: {
526+
'ngSkipHydration': 'true',
526527
'class': 'mat-mdc-tab-group',
527528
'[class.mat-mdc-tab-group-dynamic-height]': 'dynamicHeight',
528529
'[class.mat-mdc-tab-group-inverted-header]': 'headerPosition === "below"',

0 commit comments

Comments
 (0)