Skip to content

Commit fb4478b

Browse files
committed
fix(material/bottom-sheet): ensure animation event comes from container
Previous we were relying on the animation name to ensure that we only capture the correct animation. These changes harden it by also checking the event's `target`. (cherry picked from commit cd10a97)
1 parent ebca801 commit fb4478b

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

goldens/material/bottom-sheet/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
8383
enter(): void;
8484
exit(): void;
8585
// (undocumented)
86-
protected _handleAnimationEvent(isStart: boolean, animationName: string): void;
86+
protected _handleAnimationEvent(isStart: boolean, animationName: string, target: EventTarget | null): void;
8787
// (undocumented)
8888
ngOnDestroy(): void;
8989
// (undocumented)

src/material/bottom-sheet/bottom-sheet-container.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ const EXIT_ANIMATION = '_mat-bottom-sheet-exit';
4646
'[attr.role]': '_config.role',
4747
'[attr.aria-modal]': '_config.ariaModal',
4848
'[attr.aria-label]': '_config.ariaLabel',
49-
'(animationstart)': '_handleAnimationEvent(true, $event.animationName)',
50-
'(animationend)': '_handleAnimationEvent(false, $event.animationName)',
51-
'(animationcancel)': '_handleAnimationEvent(false, $event.animationName)',
49+
'(animationstart)': '_handleAnimationEvent(true, $event.animationName, $event.target)',
50+
'(animationend)': '_handleAnimationEvent(false, $event.animationName, $event.target)',
51+
'(animationcancel)': '_handleAnimationEvent(false, $event.animationName, $event.target)',
5252
},
5353
imports: [CdkPortalOutlet],
5454
})
@@ -125,8 +125,8 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
125125

126126
private _simulateAnimation(name: typeof ENTER_ANIMATION | typeof EXIT_ANIMATION) {
127127
this._ngZone.run(() => {
128-
this._handleAnimationEvent(true, name);
129-
setTimeout(() => this._handleAnimationEvent(false, name));
128+
this._handleAnimationEvent(true, name, this._elementRef.nativeElement);
129+
setTimeout(() => this._handleAnimationEvent(false, name, this._elementRef.nativeElement));
130130
});
131131
}
132132

@@ -139,15 +139,21 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
139139
super._trapFocus({preventScroll: true});
140140
}
141141

142-
protected _handleAnimationEvent(isStart: boolean, animationName: string) {
143-
const isEnter = animationName === ENTER_ANIMATION;
144-
const isExit = animationName === EXIT_ANIMATION;
145-
146-
if (isEnter || isExit) {
147-
this._animationStateChanged.emit({
148-
toState: isEnter ? 'visible' : 'hidden',
149-
phase: isStart ? 'start' : 'done',
150-
});
142+
protected _handleAnimationEvent(
143+
isStart: boolean,
144+
animationName: string,
145+
target: EventTarget | null,
146+
) {
147+
if (target === this._elementRef.nativeElement) {
148+
const isEnter = animationName === ENTER_ANIMATION;
149+
const isExit = animationName === EXIT_ANIMATION;
150+
151+
if (isEnter || isExit) {
152+
this._animationStateChanged.emit({
153+
toState: isEnter ? 'visible' : 'hidden',
154+
phase: isStart ? 'start' : 'done',
155+
});
156+
}
151157
}
152158
}
153159
}

0 commit comments

Comments
 (0)