Skip to content

Commit b7c377b

Browse files
committed
fixup! fix(material/select): switch away from animations module
1 parent a44b347 commit b7c377b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/material/select/select.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
[cdkConnectedOverlayPositions]="_positions"
4141
[cdkConnectedOverlayWidth]="_overlayWidth"
4242
(backdropClick)="close()"
43-
(detach)="openedChange.emit(false)">
43+
(overlayKeydown)="_handleOverlayKeydown($event)">
4444
<div
4545
#panel
4646
role="listbox"
@@ -52,7 +52,6 @@
5252
[attr.aria-label]="ariaLabel || null"
5353
[attr.aria-labelledby]="_getPanelAriaLabelledby()"
5454
[ngClass]="panelClass"
55-
(animationend)="_handleAnimationEndEvent($event)"
5655
(keydown)="_handleKeydown($event)">
5756
<ng-content></ng-content>
5857
</div>

src/material/select/select.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,8 @@ export class MatSelect
757757
// Required for the MDC form field to pick up when the overlay has been opened.
758758
this.stateChanges.next();
759759

760-
// This usually fires at the end of the animation,
761-
// but that won't happen if animations are disabled.
762-
if (this._animationsDisabled) {
763-
this.openedChange.emit(true);
764-
}
760+
// Simulate the animation event before we moved away from `@angular/animations`.
761+
Promise.resolve().then(() => this.openedChange.emit(true));
765762
}
766763

767764
/**
@@ -839,6 +836,9 @@ export class MatSelect
839836
this._onTouched();
840837
// Required for the MDC form field to pick up when the overlay has been closed.
841838
this.stateChanges.next();
839+
840+
// Simulate the animation event before we moved away from `@angular/animations`.
841+
Promise.resolve().then(() => this.openedChange.emit(false));
842842
}
843843
}
844844

@@ -1006,7 +1006,7 @@ export class MatSelect
10061006
const isArrowKey = keyCode === DOWN_ARROW || keyCode === UP_ARROW;
10071007
const isTyping = manager.isTyping();
10081008

1009-
if ((isArrowKey && event.altKey) || (keyCode === ESCAPE && !hasModifierKey(event))) {
1009+
if (isArrowKey && event.altKey) {
10101010
// Close the select on ALT + arrow key to match the native <select>
10111011
event.preventDefault();
10121012
this.close();
@@ -1046,6 +1046,18 @@ export class MatSelect
10461046
}
10471047
}
10481048

1049+
/** Handles keyboard events coming from the overlay. */
1050+
protected _handleOverlayKeydown(event: KeyboardEvent): void {
1051+
// TODO(crisbeto): prior to #30363 this was being handled inside the overlay directive, but we
1052+
// need control over the animation timing so we do it manually. We should remove the `keydown`
1053+
// listener from `.mat-mdc-select-panel` and handle all the events here. That may cause
1054+
// further test breakages so it's left for a follow-up.
1055+
if (event.keyCode === ESCAPE && !hasModifierKey(event)) {
1056+
event.preventDefault();
1057+
this.close();
1058+
}
1059+
}
1060+
10491061
_onFocus() {
10501062
if (!this.disabled) {
10511063
this._focused = true;
@@ -1078,13 +1090,6 @@ export class MatSelect
10781090
return !this._selectionModel || this._selectionModel.isEmpty();
10791091
}
10801092

1081-
/** Handles animation events from the panel. */
1082-
protected _handleAnimationEndEvent(event: AnimationEvent) {
1083-
if (event.target === this.panel.nativeElement && event.animationName === '_mat-select-enter') {
1084-
this.openedChange.emit(true);
1085-
}
1086-
}
1087-
10881093
private _initializeSelection(): void {
10891094
// Defer setting the value in order to avoid the "Expression
10901095
// has changed after it was checked" errors from Angular.

tools/public_api_guard/material/select.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
114114
_getAriaActiveDescendant(): string | null;
115115
_getPanelAriaLabelledby(): string | null;
116116
_getPanelTheme(): string;
117-
protected _handleAnimationEndEvent(event: AnimationEvent): void;
118117
_handleKeydown(event: KeyboardEvent): void;
118+
protected _handleOverlayKeydown(event: KeyboardEvent): void;
119119
get hideSingleSelectionIndicator(): boolean;
120120
set hideSingleSelectionIndicator(value: boolean);
121121
get id(): string;

0 commit comments

Comments
 (0)