Skip to content

Commit f59abdb

Browse files
amcdnlmmalerba
authored andcommitted
fix(select): make @output names consistent #6677 (#8052)
1 parent d47b37a commit f59abdb

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/lib/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3390,7 +3390,7 @@ class NgIfSelect {
33903390
selector: 'select-with-change-event',
33913391
template: `
33923392
<mat-form-field>
3393-
<mat-select (change)="changeListener($event)">
3393+
<mat-select (selectionChange)="changeListener($event)">
33943394
<mat-option *ngFor="let food of foods" [value]="food">{{ food }}</mat-option>
33953395
</mat-select>
33963396
</mat-form-field>

src/lib/select/select.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ScrollStrategy,
1919
ViewportRuler,
2020
} from '@angular/cdk/overlay';
21-
import {filter, first, startWith, takeUntil} from 'rxjs/operators';
21+
import {filter, first, map, startWith, takeUntil} from 'rxjs/operators';
2222
import {
2323
AfterContentInit,
2424
Attribute,
@@ -401,14 +401,41 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
401401
return merge(...this.options.map(option => option.onSelectionChange));
402402
}
403403

404-
/** Event emitted when the select has been opened. */
405-
@Output() onOpen: EventEmitter<void> = new EventEmitter<void>();
404+
/** Event emitted when the select has been opened. */
405+
@Output() openedChange: EventEmitter<boolean> = new EventEmitter<boolean>();
406+
407+
/** Event emitted when the select has been opened. */
408+
@Output('opened')
409+
get _openedStream(): Observable<void> {
410+
return this.openedChange.pipe(filter(o => o), map(() => {}));
411+
}
406412

407413
/** Event emitted when the select has been closed. */
408-
@Output() onClose: EventEmitter<void> = new EventEmitter<void>();
414+
@Output('closed')
415+
get _closedStream(): Observable<void> {
416+
return this.openedChange.pipe(filter(o => !o), map(() => {}));
417+
}
418+
419+
/**
420+
* Event emitted when the select has been opened.
421+
* @deprecated Use `openedChange` instead.
422+
*/
423+
@Output() onOpen: Observable<void> = this._openedStream;
409424

410-
/** Event emitted when the selected value has been changed by the user. */
411-
@Output() change: EventEmitter<MatSelectChange> = new EventEmitter<MatSelectChange>();
425+
/**
426+
* Event emitted when the select has been closed.
427+
* @deprecated Use `openedChange` instead.
428+
*/
429+
@Output() onClose: Observable<void> = this._closedStream;
430+
431+
/** Event emitted when the selected value has been changed by the user. */
432+
@Output() selectionChange: EventEmitter<MatSelectChange> = new EventEmitter<MatSelectChange>();
433+
434+
/**
435+
* Event emitted when the selected value has been changed by the user.
436+
* @deprecated Use `selectionChange` instead.
437+
*/
438+
@Output() change: EventEmitter<MatSelectChange> = this.selectionChange;
412439

413440
/**
414441
* Event that emits whenever the raw value of the select changes. This is here primarily
@@ -637,9 +664,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
637664
_onPanelDone(): void {
638665
if (this.panelOpen) {
639666
this._scrollTop = 0;
640-
this.onOpen.emit();
667+
this.openedChange.emit(true);
641668
} else {
642-
this.onClose.emit();
669+
this.openedChange.emit(false);
643670
this._panelDoneAnimating = false;
644671
this.overlayDir.offsetX = 0;
645672
this._changeDetectorRef.markForCheck();
@@ -859,7 +886,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
859886

860887
this._value = valueToEmit;
861888
this._onChange(valueToEmit);
862-
this.change.emit(new MatSelectChange(this, valueToEmit));
889+
this.selectionChange.emit(new MatSelectChange(this, valueToEmit));
863890
this.valueChange.emit(valueToEmit);
864891
this._changeDetectorRef.markForCheck();
865892
}

0 commit comments

Comments
 (0)