Skip to content

Commit fe151e6

Browse files
crisbetojelbourn
authored andcommitted
fix(input): avoid multiple autosize input listeners with ivy (#17817)
Avoids double event listeners for the Material autosize directive, because Ivy merges inherited metadata, whereas ViewEngine overrides. We've made similar fixes in other places, but we probably missed this one because it doesn't break anything.
1 parent 73d1ceb commit fe151e6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/cdk/text-field/autosize.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
DoCheck,
1616
OnDestroy,
1717
NgZone,
18+
HostListener,
1819
} from '@angular/core';
1920
import {Platform} from '@angular/cdk/platform';
2021
import {auditTime, takeUntil} from 'rxjs/operators';
@@ -30,7 +31,6 @@ import {fromEvent, Subject} from 'rxjs';
3031
// Textarea elements that have the directive applied should have a single row by default.
3132
// Browsers normally show two rows by default and therefore this limits the minRows binding.
3233
'rows': '1',
33-
'(input)': '_noopInputHandler()',
3434
},
3535
})
3636
export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
@@ -250,6 +250,11 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
250250
this._textareaElement.style.height = this._initialHeight;
251251
}
252252

253+
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
254+
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
255+
// can move this back into `host`.
256+
// tslint:disable:no-host-decorator-in-concrete
257+
@HostListener('input')
253258
_noopInputHandler() {
254259
// no-op handler that ensures we're running change detection on input events.
255260
}

src/material/input/autosize.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {Directive, Input} from '@angular/core';
2323
// Textarea elements that have the directive applied should have a single row by default.
2424
// Browsers normally show two rows by default and therefore this limits the minRows binding.
2525
'rows': '1',
26-
'(input)': '_noopInputHandler()',
2726
},
2827
})
2928
export class MatTextareaAutosize extends CdkTextareaAutosize {

0 commit comments

Comments
 (0)