Skip to content

Commit e6b6384

Browse files
authored
chore: update MDC to latest canary (#17760)
* chore: update MDC to latest canary * address feedback
1 parent 8fd9d7d commit e6b6384

File tree

9 files changed

+560
-533
lines changed

9 files changed

+560
-533
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@types/youtube": "^0.0.38",
5454
"@webcomponents/custom-elements": "^1.1.0",
5555
"core-js": "^2.6.9",
56-
"material-components-web": "^4.0.0",
56+
"material-components-web": "5.0.0-canary.5729943ba.0",
5757
"rxjs": "^6.5.3",
5858
"systemjs": "0.19.43",
5959
"tslib": "^1.10.0",

packages.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# all in-sync. This map is passed to each ng_package rule to stamp out the appropriate
33
# version for the placeholders.
44
ANGULAR_PACKAGE_VERSION = "^9.0.0-0 || ^10.0.0-0"
5-
MDC_PACKAGE_VERSION = "^4.0.0"
5+
MDC_PACKAGE_VERSION = "5.0.0-canary.5729943ba.0"
66
VERSION_PLACEHOLDER_REPLACEMENTS = {
77
"0.0.0-MDC": MDC_PACKAGE_VERSION,
88
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,

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

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

9-
import {
10-
ChangeDetectorRef,
11-
Directive,
12-
ElementRef,
13-
} from '@angular/core';
9+
import {ChangeDetectorRef, Directive, ElementRef, OnDestroy} from '@angular/core';
1410
import {
1511
CanDisable,
1612
CanDisableCtor,
@@ -106,20 +102,32 @@ const _MatChipRemoveMixinBase:
106102
'mat-mdc-chip-remove mat-mdc-chip-trailing-icon mdc-chip__icon mdc-chip__icon--trailing',
107103
'[tabIndex]': 'tabIndex',
108104
'role': 'button',
109-
'(click)': 'interaction.next($event)',
110-
'(keydown)': 'interaction.next($event)',
105+
'(click)': '_clicks.next($event)',
106+
'(keydown)': '_keydowns.next($event)',
111107
}
112108
})
113-
export class MatChipRemove extends _MatChipRemoveMixinBase implements CanDisable, HasTabIndex {
109+
export class MatChipRemove extends _MatChipRemoveMixinBase
110+
implements CanDisable, HasTabIndex, OnDestroy {
114111
/**
115-
* Emits when the user interacts with the icon.
112+
* Emits when the user clicks the icon.
116113
* @docs-private
117114
*/
118-
interaction: Subject<MouseEvent | KeyboardEvent> = new Subject<MouseEvent | KeyboardEvent>();
115+
_clicks: Subject<MouseEvent> = new Subject<MouseEvent>();
116+
117+
/**
118+
* Emits when the user presses a key on the icon.
119+
* @docs-private
120+
*/
121+
_keydowns: Subject<KeyboardEvent> = new Subject<KeyboardEvent>();
119122

120123
constructor(_elementRef: ElementRef) {
121124
super(_elementRef);
122125
}
123126

127+
ngOnDestroy() {
128+
this._clicks.complete();
129+
this._keydowns.complete();
130+
}
131+
124132
static ngAcceptInputType_disabled: boolean | string | null | undefined;
125133
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class MatChipOption extends MatChip {
202202
if (this.disabled) {
203203
event.preventDefault();
204204
} else {
205-
this._handleInteraction(event);
205+
this._handleClick(event);
206206
event.stopPropagation();
207207
}
208208
}
@@ -221,7 +221,7 @@ export class MatChipOption extends MatChip {
221221
event.preventDefault();
222222
break;
223223
default:
224-
this._handleInteraction(event);
224+
this._handleKeydown(event);
225225
}
226226
}
227227

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
6262
cells!: HTMLElement[];
6363

6464
/** Key codes for which this component has a custom handler. */
65-
HANDLED_KEYS = NAVIGATION_KEYS.concat([BACKSPACE, DELETE]);
65+
HANDLED_KEYS = new Set([...NAVIGATION_KEYS, BACKSPACE, DELETE]);
6666

6767
ngAfterContentInit() {
6868
super.ngAfterContentInit();
@@ -145,7 +145,7 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
145145
event.preventDefault();
146146
break;
147147
default:
148-
this._handleInteraction(event);
148+
this._handleKeydown(event);
149149
}
150150
}
151151

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
120120
/** Emits when the chip is blurred. */
121121
readonly _onBlur = new Subject<MatChipEvent>();
122122

123-
readonly HANDLED_KEYS: number[] = [];
123+
readonly HANDLED_KEYS: Set<number> = new Set();
124124

125125
/** Whether the chip has focus. */
126126
protected _hasFocusInternal = false;
@@ -330,24 +330,29 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
330330
_initRemoveIcon() {
331331
if (this.removeIcon) {
332332
this._chipFoundation.setShouldRemoveOnTrailingIconClick(true);
333-
this._listenToRemoveIconInteraction();
333+
this._listenToRemoveIconInteractions();
334334
this.removeIcon.disabled = this.disabled;
335335
}
336336
}
337337

338338
/** Handles interaction with the remove icon. */
339-
_listenToRemoveIconInteraction() {
340-
this.removeIcon.interaction
339+
_listenToRemoveIconInteractions() {
340+
this.removeIcon._clicks
341341
.pipe(takeUntil(this._destroyed))
342-
.subscribe((event) => {
342+
.subscribe(event => {
343+
if (!this.disabled) {
344+
this._chipFoundation.handleClick(event);
345+
}
346+
});
347+
this.removeIcon._keydowns
348+
.pipe(takeUntil(this._destroyed))
349+
.subscribe(event => {
343350
// The MDC chip foundation calls stopPropagation() for any trailing icon interaction
344351
// event, even ones it doesn't handle, so we want to avoid passing it keyboard events
345352
// for which we have a custom handler.
346-
if (this.disabled || (event instanceof KeyboardEvent &&
347-
this.HANDLED_KEYS.indexOf(event.keyCode) !== -1)) {
348-
return;
353+
if (!this.disabled && !this.HANDLED_KEYS.has(event.keyCode)) {
354+
this._chipFoundation.handleKeydown(event);
349355
}
350-
this._chipFoundation.handleTrailingIconInteraction(event);
351356
});
352357
}
353358

@@ -391,10 +396,17 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
391396
this._rippleRenderer.setupTriggerEvents(this._elementRef);
392397
}
393398

394-
/** Forwards interaction events to the MDC chip foundation. */
395-
_handleInteraction(event: MouseEvent | KeyboardEvent) {
399+
/** Forwards click events to the MDC chip foundation. */
400+
_handleClick(event: MouseEvent) {
401+
if (!this.disabled) {
402+
this._chipFoundation.handleClick(event);
403+
}
404+
}
405+
406+
/** Forwards keydown events to the MDC chip foundation. */
407+
_handleKeydown(event: KeyboardEvent) {
396408
if (!this.disabled) {
397-
this._chipFoundation.handleInteraction(event);
409+
this._chipFoundation.handleKeydown(event);
398410
}
399411
}
400412

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ng_module(
1818
# Add all MDC Sass files that we depend on here. After updating MDC dependencies, use the following
1919
# command to generate an updated list:
2020
#
21-
# `find node_modules/@material/ -name "_*.scss" | sort | sed -r 's/(.*\/@material\/[^/]*)\/(.*)/"@npm\/\/\1:\2",/'`
21+
# `find node_modules/@material/ -name "_*.scss" | sort | sed -r 's/(.*)/"@npm\/\/:\1",/'`
2222
#
2323
# TODO(mmalerba): Find a less tedious way to do this...
2424
sass_library(
@@ -45,6 +45,7 @@ sass_library(
4545
"@npm//:node_modules/@material/dialog/_variables.scss",
4646
"@npm//:node_modules/@material/drawer/_mixins.scss",
4747
"@npm//:node_modules/@material/drawer/_variables.scss",
48+
"@npm//:node_modules/@material/elevation/_functions.scss",
4849
"@npm//:node_modules/@material/elevation/_mixins.scss",
4950
"@npm//:node_modules/@material/elevation/_variables.scss",
5051
"@npm//:node_modules/@material/fab/_mixins.scss",
@@ -108,6 +109,7 @@ sass_library(
108109
"@npm//:node_modules/@material/tab-bar/_variables.scss",
109110
"@npm//:node_modules/@material/tab-indicator/_mixins.scss",
110111
"@npm//:node_modules/@material/tab-scroller/_mixins.scss",
112+
"@npm//:node_modules/@material/tab-scroller/_variables.scss",
111113
"@npm//:node_modules/@material/tab/_mixins.scss",
112114
"@npm//:node_modules/@material/tab/_variables.scss",
113115
"@npm//:node_modules/@material/textfield/_functions.scss",

src/material-experimental/mdc-progress-bar/progress-bar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
8686
removeClass: (className: string) => this._rootElement.classList.remove(className),
8787
setStyle: (el: HTMLElement, styleProperty: string, value: string) => {
8888
(el.style as any)[styleProperty] = value;
89-
}
89+
},
90+
removeAttribute: (name: string) => this._elementRef.nativeElement.removeAttribute(name),
91+
setAttribute: (name: string, value: string) =>
92+
this._elementRef.nativeElement.setAttribute(name, value),
9093
};
9194

9295
/** Flag that indicates whether NoopAnimations mode is set to true. */

0 commit comments

Comments
 (0)