Skip to content

Commit cfc3746

Browse files
committed
Revert "Update MDC to latest alpha (#16724)" (#16770)
This reverts commit 8942602. (cherry picked from commit cc8f37f)
1 parent 5743880 commit cfc3746

File tree

9 files changed

+510
-561
lines changed

9 files changed

+510
-561
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"version": "8.1.2",
3939
"requiredAngularVersion": "^8.0.0 || ^9.0.0-0",
40-
"requiredMDCVersion": "^4.0.0-alpha.0",
40+
"requiredMDCVersion": "^3.0.0",
4141
"dependencies": {
4242
"@angular/animations": "^8.2.2",
4343
"@angular/common": "^8.2.2",
@@ -48,7 +48,7 @@
4848
"@angular/platform-browser": "^8.2.2",
4949
"@webcomponents/custom-elements": "^1.1.0",
5050
"core-js": "^2.6.1",
51-
"material-components-web": "^4.0.0-alpha.0",
51+
"material-components-web": "^3.0.0",
5252
"rxjs": "^6.4.0",
5353
"systemjs": "0.19.43",
5454
"tsickle": "^0.35.0",

src/material-experimental/mdc-chips/chip-grid.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ export class MatChipGridChange {
6060
class MatChipGridBase extends MatChipSet {
6161
constructor(_elementRef: ElementRef,
6262
_changeDetectorRef: ChangeDetectorRef,
63-
_dir: Directionality,
6463
public _defaultErrorStateMatcher: ErrorStateMatcher,
6564
public _parentForm: NgForm,
6665
public _parentFormGroup: FormGroupDirective,
6766
/** @docs-private */
6867
public ngControl: NgControl) {
69-
super(_elementRef, _changeDetectorRef, _dir);
68+
super(_elementRef, _changeDetectorRef);
7069
}
7170
}
7271
const _MatChipGridMixinBase: CanUpdateErrorStateCtor & typeof MatChipGridBase =
@@ -238,14 +237,14 @@ export class MatChipGrid extends _MatChipGridMixinBase implements AfterContentIn
238237

239238
constructor(_elementRef: ElementRef,
240239
_changeDetectorRef: ChangeDetectorRef,
241-
@Optional() _dir: Directionality,
240+
@Optional() private _dir: Directionality,
242241
@Optional() _parentForm: NgForm,
243242
@Optional() _parentFormGroup: FormGroupDirective,
244243
_defaultErrorStateMatcher: ErrorStateMatcher,
245244
/** @docs-private */
246245
@Optional() @Self() public ngControl: NgControl) {
247-
super(_elementRef, _changeDetectorRef, _dir, _defaultErrorStateMatcher, _parentForm,
248-
_parentFormGroup, ngControl);
246+
super(_elementRef, _changeDetectorRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup,
247+
ngControl);
249248
if (this.ngControl) {
250249
this.ngControl.valueAccessor = this;
251250
}

src/material-experimental/mdc-chips/chip-icons.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ import {Subject} from 'rxjs';
3535
})
3636
export class MatChipAvatar {
3737
constructor(private _changeDetectorRef: ChangeDetectorRef,
38-
private _elementRef: ElementRef<HTMLElement>) {}
38+
private _elementRef: ElementRef) {}
3939

4040
/** Sets whether the given CSS class should be applied to the leading icon. */
4141
setClass(cssClass: string, active: boolean) {
42-
this._elementRef.nativeElement.classList.toggle(cssClass, active);
42+
const element = this._elementRef.nativeElement;
43+
active ? element.addClass(cssClass) : element.removeClass(cssClass);
4344
this._changeDetectorRef.markForCheck();
4445
}
4546
}
@@ -57,25 +58,15 @@ export class MatChipAvatar {
5758
}
5859
})
5960
export class MatChipTrailingIcon {
60-
constructor(public _elementRef: ElementRef) {}
61-
62-
focus() {
63-
this._elementRef.nativeElement.focus();
64-
}
65-
66-
/** Sets an attribute on the icon. */
67-
setAttribute(name: string, value: string) {
68-
this._elementRef.nativeElement.setAttribute(name, value);
69-
}
7061
}
7162

7263
/**
7364
* Boilerplate for applying mixins to MatChipRemove.
7465
* @docs-private
7566
*/
7667
class MatChipRemoveBase extends MatChipTrailingIcon {
77-
constructor(_elementRef: ElementRef) {
78-
super(_elementRef);
68+
constructor(public _elementRef: ElementRef) {
69+
super();
7970
}
8071
}
8172

src/material-experimental/mdc-chips/chip-listbox.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {FocusKeyManager} from '@angular/cdk/a11y';
1010
import {Directionality} from '@angular/cdk/bidi';
1111
import {coerceBooleanProperty} from '@angular/cdk/coercion';
12-
import {END, HOME} from '@angular/cdk/keycodes';
12+
import {HOME, END} from '@angular/cdk/keycodes';
1313
import {
1414
AfterContentInit,
1515
ChangeDetectionStrategy,
@@ -26,7 +26,7 @@ import {
2626
ViewEncapsulation
2727
} from '@angular/core';
2828
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
29-
import {MDCChipSetFoundation} from '@material/chips';
29+
import {MDCChipSetAdapter, MDCChipSetFoundation} from '@material/chips';
3030
import {merge, Observable, Subscription} from 'rxjs';
3131
import {startWith, takeUntil} from 'rxjs/operators';
3232
import {MatChip, MatChipEvent} from './chip';
@@ -96,6 +96,22 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
9696
/** Subscription to focus changes in the chips. */
9797
private _chipFocusSubscription: Subscription | null;
9898

99+
/**
100+
* Implementation of the MDC chip-set adapter interface.
101+
* These methods are called by the chip set foundation.
102+
*
103+
* Overrides the base MatChipSet adapter to provide a setSelected method.
104+
*/
105+
protected _chipSetAdapter: MDCChipSetAdapter = {
106+
hasClass: (className: string) => this._hasMdcClass(className),
107+
// No-op. We keep track of chips via ContentChildren, which will be updated when a chip is
108+
// removed.
109+
removeChip: () => {},
110+
setSelected: (chipId: string, selected: boolean) => {
111+
this._setSelected(chipId, selected);
112+
}
113+
};
114+
99115
/** The FocusKeyManager which handles focus. */
100116
_keyManager: FocusKeyManager<MatChip>;
101117

@@ -207,11 +223,8 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
207223

208224
constructor(protected _elementRef: ElementRef,
209225
_changeDetectorRef: ChangeDetectorRef,
210-
@Optional() _dir: Directionality) {
211-
super(_elementRef, _changeDetectorRef, _dir);
212-
this._chipSetAdapter.selectChipAtIndex = (index: number, selected: boolean) => {
213-
this._setSelected(index, selected);
214-
};
226+
@Optional() private _dir: Directionality) {
227+
super(_elementRef, _changeDetectorRef);
215228
// Reinitialize the foundation with our overridden adapter
216229
this._chipSetFoundation = new MDCChipSetFoundation(this._chipSetAdapter);
217230
this._updateMdcSelectionClasses();
@@ -306,8 +319,8 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
306319
}
307320

308321
/** Selects or deselects a chip by id. */
309-
_setSelected(index: number, selected: boolean) {
310-
const chip = this._chips.toArray()[index];
322+
_setSelected(chipId: string, selected: boolean) {
323+
const chip = this._chips.find(c => c.id === chipId);
311324
if (chip && chip.selected != selected) {
312325
chip.toggleSelected(true);
313326
}
@@ -455,7 +468,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
455468

456469
/** Initializes the key manager to manage focus. */
457470
private _initKeyManager() {
458-
this._keyManager = new FocusKeyManager<MatChip>(this._chips)
471+
this._keyManager = new FocusKeyManager<MatChipOption>(this._chips)
459472
.withWrap()
460473
.withVerticalOrientation()
461474
.withHorizontalOrientation(this._dir ? this._dir.value : 'ltr');
@@ -530,7 +543,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
530543
this._chipSelectionSubscription = this.chipSelectionChanges.subscribe(
531544
(chipSelectionChange: MatChipSelectionChange) => {
532545
this._chipSetFoundation.handleChipSelection(
533-
chipSelectionChange.source.id, chipSelectionChange.selected, false);
546+
chipSelectionChange.source.id, chipSelectionChange.selected);
534547
if (chipSelectionChange.isUserInput) {
535548
this._propagateChanges();
536549
}

src/material-experimental/mdc-chips/chip-set.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directionality} from '@angular/cdk/bidi';
109
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1110
import {
1211
AfterContentInit,
@@ -18,15 +17,18 @@ import {
1817
ElementRef,
1918
Input,
2019
OnDestroy,
21-
Optional,
2220
QueryList,
2321
ViewEncapsulation
2422
} from '@angular/core';
25-
import {HasTabIndex, HasTabIndexCtor, mixinTabIndex} from '@angular/material/core';
2623
import {MDCChipSetAdapter, MDCChipSetFoundation} from '@material/chips';
24+
import {MatChip, MatChipEvent} from './chip';
2725
import {merge, Observable, Subject, Subscription} from 'rxjs';
2826
import {startWith, takeUntil} from 'rxjs/operators';
29-
import {MatChip, MatChipEvent} from './chip';
27+
import {
28+
HasTabIndex,
29+
HasTabIndexCtor,
30+
mixinTabIndex,
31+
} from '@angular/material/core';
3032

3133

3234
let uid = 0;
@@ -95,15 +97,9 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
9597
hasClass: (className) => this._hasMdcClass(className),
9698
// No-op. We keep track of chips via ContentChildren, which will be updated when a chip is
9799
// removed.
98-
removeChipAtIndex: () => {},
100+
removeChip: () => {},
99101
// No-op for base chip set. MatChipListbox overrides the adapter to provide this method.
100-
selectChipAtIndex: () => {},
101-
getIndexOfChipById: (id: string) => this._chips.toArray().findIndex(chip => chip.id === id),
102-
focusChipPrimaryActionAtIndex: () => {},
103-
focusChipTrailingActionAtIndex: () => {},
104-
removeFocusFromChipAtIndex: () => {},
105-
isRTL: () => !!this._dir && this._dir.value === 'rtl',
106-
getChipListCount: () => this._chips.length,
102+
setSelected: () => {}
107103
};
108104

109105
/** The aria-describedby attribute on the chip list for improved a11y. */
@@ -155,8 +151,7 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
155151
@ContentChildren(MatChip) _chips: QueryList<MatChip>;
156152

157153
constructor(protected _elementRef: ElementRef,
158-
protected _changeDetectorRef: ChangeDetectorRef,
159-
@Optional() protected _dir: Directionality) {
154+
protected _changeDetectorRef: ChangeDetectorRef) {
160155
super(_elementRef);
161156
this._chipSetFoundation = new MDCChipSetFoundation(this._chipSetAdapter);
162157
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
2-
<div class="mdc-chip__text mdc-chip__action--primary"><ng-content></ng-content></div>
2+
<div class="mdc-chip__text"><ng-content></ng-content></div>
33
<ng-content select="mat-chip-trailing-icon,[matChipRemove],[matChipTrailingIcon]"></ng-content>

src/material-experimental/mdc-chips/chip.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directionality} from '@angular/cdk/bidi';
109
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1110
import {Platform} from '@angular/cdk/platform';
1211
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
@@ -248,38 +247,28 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
248247
// No-op. We call dispatchSelectionEvent ourselves in MatChipOption, because we want to
249248
// specify whether selection occurred via user input.
250249
},
251-
notifyNavigation: () => {
252-
// TODO: This is a new feature added by MDC, consider exposing this event to users in the
253-
// future.
254-
},
255250
notifyTrailingIconInteraction: () => this.removeIconInteraction.emit(this.id),
256251
notifyRemoval: () => this.removed.emit({chip: this}),
257-
getComputedStyleValue: propertyName =>
258-
window.getComputedStyle(this._elementRef.nativeElement).getPropertyValue(propertyName),
252+
getComputedStyleValue: (propertyName) => {
253+
return window.getComputedStyle(this._elementRef.nativeElement).getPropertyValue(propertyName);
254+
},
259255
setStyleProperty: (propertyName: string, value: string) => {
260256
this._elementRef.nativeElement.style.setProperty(propertyName, value);
261257
},
262-
hasLeadingIcon: () => !!this.leadingIcon,
263-
hasTrailingAction: () => !!this.trailingIcon,
264-
isRTL: () => !!this._dir && this._dir.value === 'rtl',
265-
focusPrimaryAction: () => this._elementRef.nativeElement.focus(),
266-
focusTrailingAction: () => this.trailingIcon && this.trailingIcon.focus(),
267-
setTrailingActionAttr: (attr, value) =>
268-
this.trailingIcon && this.trailingIcon.setAttribute(attr, value),
269-
setPrimaryActionAttr: (name: string, value: string) => {
258+
hasLeadingIcon: () => { return !!this.leadingIcon; },
259+
setAttr: (name: string, value: string) => {
270260
// MDC is currently using this method to set aria-checked on choice and filter chips,
271261
// which in the MDC templates have role="checkbox" and role="radio" respectively.
272262
// We have role="option" on those chips instead, so we do not want aria-checked.
273-
// Since we also manage the tabindex ourselves, we don't allow MDC to set it.
274-
if (name === 'aria-checked' || name === 'tabindex') {
263+
if (name === 'aria-checked') {
275264
return;
276265
}
277266
this._elementRef.nativeElement.setAttribute(name, value);
278267
},
279268
// The 2 functions below are used by the MDC ripple, which we aren't using,
280269
// so they will never be called
281270
getRootBoundingClientRect: () => this._elementRef.nativeElement.getBoundingClientRect(),
282-
getCheckmarkBoundingClientRect: () => null,
271+
getCheckmarkBoundingClientRect: () => { return null; },
283272
};
284273

285274
constructor(
@@ -289,7 +278,6 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
289278
protected _ngZone: NgZone,
290279
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
291280
private _globalRippleOptions: RippleGlobalOptions | null,
292-
@Optional() private _dir: Directionality,
293281
// @breaking-change 8.0.0 `animationMode` parameter to become required.
294282
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
295283
super(_elementRef);

src/material-experimental/mdc-helpers/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ sass_library(
118118
"@npm//:node_modules/@material/theme/_variables.scss",
119119
"@npm//:node_modules/@material/top-app-bar/_mixins.scss",
120120
"@npm//:node_modules/@material/top-app-bar/_variables.scss",
121-
"@npm//:node_modules/@material/touch-target/_mixins.scss",
122-
"@npm//:node_modules/@material/touch-target/_variables.scss",
123121
"@npm//:node_modules/@material/typography/_functions.scss",
124122
"@npm//:node_modules/@material/typography/_mixins.scss",
125123
"@npm//:node_modules/@material/typography/_variables.scss",

0 commit comments

Comments
 (0)