Skip to content

Commit d299a31

Browse files
mmalerbajelbourn
authored andcommitted
chore(ivy): fix host listener inheritence for mdc-chips and mdc-anchor (#17790)
1 parent 71165f1 commit d299a31

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/material-experimental/mdc-button/button-base.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
*/
88

99
import {Platform} from '@angular/cdk/platform';
10-
import {Directive, ElementRef, Inject, NgZone, Optional, ViewChild} from '@angular/core';
10+
import {
11+
Directive,
12+
ElementRef,
13+
HostListener,
14+
Inject,
15+
NgZone,
16+
Optional,
17+
ViewChild
18+
} from '@angular/core';
1119
import {
1220
CanColor,
1321
CanColorCtor,
@@ -141,7 +149,6 @@ export const MAT_ANCHOR_HOST = {
141149
// though they have an index, they're not tabbable.
142150
'[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)',
143151
'[attr.aria-disabled]': 'disabled.toString()',
144-
'(click)': '_haltDisabledEvents($event)',
145152
// MDC automatically applies the primary theme color to the button, but we want to support
146153
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
147154
// select and style this "theme".
@@ -161,6 +168,12 @@ export class MatAnchorBase extends MatButtonBase {
161168
super(elementRef, platform, ngZone, animationMode);
162169
}
163170

171+
// We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
172+
// In Ivy the `host` bindings will be merged when this class is extended, whereas in
173+
// ViewEngine they're overwritten.
174+
// TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
175+
// tslint:disable-next-line:no-host-decorator-in-concrete
176+
@HostListener('click', ['$event'])
164177
_haltDisabledEvents(event: Event) {
165178
// A disabled button shouldn't apply any actions
166179
if (this.disabled) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export class MatChipSelectionChange {
5656
'(keydown)': '_keydown($event)',
5757
'(focus)': 'focus()',
5858
'(blur)': '_blur()',
59-
'(transitionend)': '_chipFoundation.handleTransitionEnd($event)'
6059
},
6160
providers: [{provide: MatChip, useExisting: MatChipOption}],
6261
encapsulation: ViewEncapsulation.None,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {GridKeyManagerRow, NAVIGATION_KEYS} from './grid-key-manager';
4141
'[tabIndex]': 'tabIndex',
4242
'(mousedown)': '_mousedown($event)',
4343
'(keydown)': '_keydown($event)',
44-
'(transitionend)': '_chipFoundation.handleTransitionEnd($event)',
4544
'(focusin)': '_focusin()',
4645
'(focusout)': '_focusout()'
4746
},

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
OnDestroy,
2727
Optional,
2828
Output,
29-
ViewEncapsulation
29+
ViewEncapsulation, HostListener
3030
} from '@angular/core';
3131
import {
3232
CanColor,
@@ -108,7 +108,6 @@ const _MatChipMixinBase:
108108
'[id]': 'id',
109109
'[attr.disabled]': 'disabled || null',
110110
'[attr.aria-disabled]': 'disabled.toString()',
111-
'(transitionend)': '_chipFoundation.handleTransitionEnd($event)'
112111
},
113112
encapsulation: ViewEncapsulation.None,
114113
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -129,6 +128,16 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
129128
/** Whether animations for the chip are enabled. */
130129
_animationsDisabled: boolean;
131130

131+
// We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
132+
// In Ivy the `host` bindings will be merged when this class is extended, whereas in
133+
// ViewEngine they're overwritten.
134+
// TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
135+
// tslint:disable-next-line:no-host-decorator-in-concrete
136+
@HostListener('transitionend', ['$event'])
137+
_handleTransitionEnd(event: TransitionEvent) {
138+
this._chipFoundation.handleTransitionEnd(event);
139+
}
140+
132141
get _hasFocus() {
133142
return this._hasFocusInternal;
134143
}

0 commit comments

Comments
 (0)