Skip to content

Commit 274416b

Browse files
authored
fix(bottom-sheet): allow result to be passed when dismissing through service (#18831)
A bottom sheet can be dismissed both through the bottom sheet ref and the service, but we only allow a result to be passed through the ref. These changes add a paramter to the service as well.
1 parent 124ea5a commit 274416b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,20 @@ describe('MatBottomSheet', () => {
400400
expect(spy).toHaveBeenCalledWith(1337);
401401
}));
402402

403+
it('should be able to pass data when dismissing through the service', fakeAsync(() => {
404+
const bottomSheetRef = bottomSheet.open<PizzaMsg, any, number>(PizzaMsg);
405+
const spy = jasmine.createSpy('afterDismissed spy');
406+
407+
bottomSheetRef.afterDismissed().subscribe(spy);
408+
viewContainerFixture.detectChanges();
409+
410+
bottomSheet.dismiss(1337);
411+
viewContainerFixture.detectChanges();
412+
flush();
413+
414+
expect(spy).toHaveBeenCalledWith(1337);
415+
}));
416+
403417
it('should close the bottom sheet when going forwards/backwards in history', fakeAsync(() => {
404418
bottomSheet.open(PizzaMsg);
405419

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ export class MatBottomSheet implements OnDestroy {
112112

113113
/**
114114
* Dismisses the currently-visible bottom sheet.
115+
* @param result Data to pass to the bottom sheet instance.
115116
*/
116-
dismiss(): void {
117+
dismiss<R = any>(result?: R): void {
117118
if (this._openedBottomSheetRef) {
118-
this._openedBottomSheetRef.dismiss();
119+
this._openedBottomSheetRef.dismiss(result);
119120
}
120121
}
121122

tools/public_api_guard/material/bottom-sheet.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export declare class MatBottomSheet implements OnDestroy {
66
get _openedBottomSheetRef(): MatBottomSheetRef<any> | null;
77
set _openedBottomSheetRef(value: MatBottomSheetRef<any> | null);
88
constructor(_overlay: Overlay, _injector: Injector, _parentBottomSheet: MatBottomSheet, _location?: Location | undefined, _defaultOptions?: MatBottomSheetConfig<any> | undefined);
9-
dismiss(): void;
9+
dismiss<R = any>(result?: R): void;
1010
ngOnDestroy(): void;
1111
open<T, D = any, R = any>(component: ComponentType<T>, config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;
1212
open<T, D = any, R = any>(template: TemplateRef<T>, config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;

0 commit comments

Comments
 (0)