Skip to content

Commit 956aec2

Browse files
committed
feat(material/bottom-sheet): expose rendered ComponentRef
Exposes the `ComponentRef` to the component that is rendered inside of a bottom sheet container. This allows users to interact with the component's inputs.
1 parent 30c3e13 commit 956aec2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {ComponentRef} from '@angular/core';
910
import {DialogRef} from '@angular/cdk/dialog';
1011
import {ESCAPE, hasModifierKey} from '@angular/cdk/keycodes';
1112
import {merge, Observable, Subject} from 'rxjs';
@@ -22,6 +23,14 @@ export class MatBottomSheetRef<T = any, R = any> {
2223
return this._ref.componentInstance!;
2324
}
2425

26+
/**
27+
* `ComponentRef` of the component opened into the bottom sheet. Will be
28+
* null when the bottom sheet is opened using a `TemplateRef`.
29+
*/
30+
get componentRef(): ComponentRef<T> | null {
31+
return this._ref.componentRef;
32+
}
33+
2534
/**
2635
* Instance of the component into which the bottom sheet content is projected.
2736
* @docs-private

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Location} from '@angular/common';
88
import {SpyLocation} from '@angular/common/testing';
99
import {
1010
Component,
11+
ComponentRef,
1112
Directive,
1213
Inject,
1314
Injector,
@@ -83,6 +84,7 @@ describe('MatBottomSheet', () => {
8384

8485
expect(overlayContainerElement.textContent).toContain('Pizza');
8586
expect(bottomSheetRef.instance instanceof PizzaMsg).toBe(true);
87+
expect(bottomSheetRef.componentRef instanceof ComponentRef).toBe(true);
8688
expect(bottomSheetRef.instance.bottomSheetRef).toBe(bottomSheetRef);
8789
});
8890

tools/public_api_guard/material/bottom-sheet.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AnimationTriggerMetadata } from '@angular/animations';
99
import { BreakpointObserver } from '@angular/cdk/layout';
1010
import { CdkDialogContainer } from '@angular/cdk/dialog';
1111
import { ChangeDetectorRef } from '@angular/core';
12+
import { ComponentRef } from '@angular/core';
1213
import { ComponentType } from '@angular/cdk/portal';
1314
import { DialogConfig } from '@angular/cdk/dialog';
1415
import { DialogRef } from '@angular/cdk/dialog';
@@ -117,6 +118,7 @@ export class MatBottomSheetRef<T = any, R = any> {
117118
afterDismissed(): Observable<R | undefined>;
118119
afterOpened(): Observable<void>;
119120
backdropClick(): Observable<MouseEvent>;
121+
get componentRef(): ComponentRef<T> | null;
120122
containerInstance: MatBottomSheetContainer;
121123
disableClose: boolean | undefined;
122124
dismiss(result?: R): void;

0 commit comments

Comments
 (0)