Skip to content

Commit 8abb33d

Browse files
authored
refactor(material/select): Remove use of zone onStable to wait for options (#28637)
1 parent b43c73c commit 8abb33d

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/material/select/select.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {
1010
ActiveDescendantKeyManager,
11-
LiveAnnouncer,
1211
addAriaReferencedId,
12+
LiveAnnouncer,
1313
removeAriaReferencedId,
1414
} from '@angular/cdk/a11y';
1515
import {Directionality} from '@angular/cdk/bidi';
@@ -35,6 +35,7 @@ import {ViewportRuler} from '@angular/cdk/scrolling';
3535
import {
3636
AfterContentInit,
3737
Attribute,
38+
booleanAttribute,
3839
ChangeDetectionStrategy,
3940
ChangeDetectorRef,
4041
Component,
@@ -45,9 +46,11 @@ import {
4546
ElementRef,
4647
EventEmitter,
4748
Inject,
49+
inject,
4850
InjectionToken,
4951
Input,
5052
NgZone,
53+
numberAttribute,
5154
OnChanges,
5255
OnDestroy,
5356
OnInit,
@@ -58,9 +61,6 @@ import {
5861
SimpleChanges,
5962
ViewChild,
6063
ViewEncapsulation,
61-
booleanAttribute,
62-
inject,
63-
numberAttribute,
6464
} from '@angular/core';
6565
import {
6666
AbstractControl,
@@ -71,17 +71,17 @@ import {
7171
Validators,
7272
} from '@angular/forms';
7373
import {
74+
_countGroupLabelsBeforeOption,
7475
_ErrorStateTracker,
76+
_getOptionScrollPosition,
7577
ErrorStateMatcher,
78+
MAT_OPTGROUP,
79+
MAT_OPTION_PARENT_COMPONENT,
7680
MatOptgroup,
7781
MatOption,
7882
MatOptionSelectionChange,
79-
MAT_OPTGROUP,
80-
MAT_OPTION_PARENT_COMPONENT,
81-
_countGroupLabelsBeforeOption,
82-
_getOptionScrollPosition,
8383
} from '@angular/material/core';
84-
import {MatFormField, MatFormFieldControl, MAT_FORM_FIELD} from '@angular/material/form-field';
84+
import {MAT_FORM_FIELD, MatFormField, MatFormFieldControl} from '@angular/material/form-field';
8585
import {defer, merge, Observable, Subject} from 'rxjs';
8686
import {
8787
distinctUntilChanged,
@@ -542,6 +542,8 @@ export class MatSelect
542542
? this._defaultOptions.panelWidth
543543
: 'auto';
544544

545+
private _initialized = new Subject();
546+
545547
/** Combined stream of all of the child options' change events. */
546548
readonly optionSelectionChanges: Observable<MatOptionSelectionChange> = defer(() => {
547549
const options = this.options;
@@ -553,11 +555,8 @@ export class MatSelect
553555
);
554556
}
555557

556-
return this._ngZone.onStable.pipe(
557-
take(1),
558-
switchMap(() => this.optionSelectionChanges),
559-
);
560-
}) as Observable<MatOptionSelectionChange>;
558+
return this._initialized.pipe(switchMap(() => this.optionSelectionChanges));
559+
});
561560

562561
/** Event emitted when the select panel has been toggled. */
563562
@Output() readonly openedChange: EventEmitter<boolean> = new EventEmitter<boolean>();
@@ -587,7 +586,11 @@ export class MatSelect
587586
constructor(
588587
protected _viewportRuler: ViewportRuler,
589588
protected _changeDetectorRef: ChangeDetectorRef,
590-
protected _ngZone: NgZone,
589+
/**
590+
* @deprecated Unused param, will be removed.
591+
* @breaking-change 19.0.0
592+
*/
593+
_unusedNgZone: NgZone,
591594
defaultErrorStateMatcher: ErrorStateMatcher,
592595
readonly _elementRef: ElementRef,
593596
@Optional() private _dir: Directionality,
@@ -650,6 +653,9 @@ export class MatSelect
650653
}
651654

652655
ngAfterContentInit() {
656+
this._initialized.next();
657+
this._initialized.complete();
658+
653659
this._initKeyManager();
654660

655661
this._selectionModel.changed.pipe(takeUntil(this._destroy)).subscribe(event => {

tools/public_api_guard/material/select.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export { MatPrefix }
8686

8787
// @public (undocumented)
8888
export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit, DoCheck, ControlValueAccessor, MatFormFieldControl<any> {
89-
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef, _ngZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
89+
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef,
90+
_unusedNgZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
9091
ariaLabel: string;
9192
ariaLabelledby: string;
9293
protected _canOpen(): boolean;
@@ -153,8 +154,6 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
153154
ngOnDestroy(): void;
154155
// (undocumented)
155156
ngOnInit(): void;
156-
// (undocumented)
157-
protected _ngZone: NgZone;
158157
_onAttached(): void;
159158
_onBlur(): void;
160159
_onChange: (value: any) => void;

0 commit comments

Comments
 (0)