Skip to content

fix(bottom-sheet): allow result to be passed when dismissing through service #18831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/material/bottom-sheet/bottom-sheet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,20 @@ describe('MatBottomSheet', () => {
expect(spy).toHaveBeenCalledWith(1337);
}));

it('should be able to pass data when dismissing through the service', fakeAsync(() => {
const bottomSheetRef = bottomSheet.open<PizzaMsg, any, number>(PizzaMsg);
const spy = jasmine.createSpy('afterDismissed spy');

bottomSheetRef.afterDismissed().subscribe(spy);
viewContainerFixture.detectChanges();

bottomSheet.dismiss(1337);
viewContainerFixture.detectChanges();
flush();

expect(spy).toHaveBeenCalledWith(1337);
}));

it('should close the bottom sheet when going forwards/backwards in history', fakeAsync(() => {
bottomSheet.open(PizzaMsg);

Expand Down
5 changes: 3 additions & 2 deletions src/material/bottom-sheet/bottom-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ export class MatBottomSheet implements OnDestroy {

/**
* Dismisses the currently-visible bottom sheet.
* @param result Data to pass to the bottom sheet instance.
*/
dismiss(): void {
dismiss<R = any>(result?: R): void {
if (this._openedBottomSheetRef) {
this._openedBottomSheetRef.dismiss();
this._openedBottomSheetRef.dismiss(result);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/bottom-sheet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export declare class MatBottomSheet implements OnDestroy {
get _openedBottomSheetRef(): MatBottomSheetRef<any> | null;
set _openedBottomSheetRef(value: MatBottomSheetRef<any> | null);
constructor(_overlay: Overlay, _injector: Injector, _parentBottomSheet: MatBottomSheet, _location?: Location | undefined, _defaultOptions?: MatBottomSheetConfig<any> | undefined);
dismiss(): void;
dismiss<R = any>(result?: R): void;
ngOnDestroy(): void;
open<T, D = any, R = any>(component: ComponentType<T>, config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;
open<T, D = any, R = any>(template: TemplateRef<T>, config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;
Expand Down