Skip to content

Commit 0e1aec8

Browse files
committed
feat(material/bottom-sheet): add the ability to pass bindings
Adds the ability to pass a `Binding[]` to the component being rendered.
1 parent 1c67989 commit 0e1aec8

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import { Binding } from '@angular/core';
78
import { CdkDialogContainer } from '@angular/cdk/dialog';
89
import { ComponentRef } from '@angular/core';
910
import { ComponentType } from '@angular/cdk/portal';
@@ -53,6 +54,7 @@ export class MatBottomSheetConfig<D = any> {
5354
ariaModal?: boolean;
5455
autoFocus?: AutoFocusTarget | string | boolean;
5556
backdropClass?: string;
57+
bindings?: Binding[];
5658
closeOnNavigation?: boolean;
5759
data?: D | null;
5860
direction?: Direction;

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

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

9-
import {InjectionToken, Injector, ViewContainerRef} from '@angular/core';
9+
import {Binding, InjectionToken, Injector, ViewContainerRef} from '@angular/core';
1010
import {Direction} from '@angular/cdk/bidi';
1111
import {ScrollStrategy} from '@angular/cdk/overlay';
1212
import {RestoreFocusValue} from '@angular/cdk/dialog';
@@ -86,4 +86,10 @@ export class MatBottomSheetConfig<D = any> {
8686

8787
/** Maximum height for the bottom sheet. If a number is provided, assumes pixel units. */
8888
maxHeight?: number | string;
89+
90+
/**
91+
* Bindings to apply to the component rendered inside the dialog.
92+
* Does nothing for template-based dialogs.
93+
*/
94+
bindings?: Binding[];
8995
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import {
1717
Directive,
1818
Injectable,
1919
Injector,
20+
Input,
2021
NgModule,
2122
TemplateRef,
2223
ViewChild,
2324
ViewContainerRef,
2425
ViewEncapsulation,
2526
forwardRef,
2627
inject,
28+
inputBinding,
2729
ChangeDetectionStrategy,
2830
} from '@angular/core';
2931
import {ComponentFixture, TestBed} from '@angular/core/testing';
@@ -506,6 +508,15 @@ describe('MatBottomSheet', () => {
506508
expect(bottomSheetRef.instance.data).toBeNull();
507509
}).not.toThrow();
508510
});
511+
512+
it('should be able to apply bindings', () => {
513+
const bottomSheetRef = bottomSheet.open(PizzaMsg, {
514+
bindings: [inputBinding('flavor', () => 'pepperoni')],
515+
});
516+
viewContainerFixture.detectChanges();
517+
518+
expect(bottomSheetRef.instance.flavor).toBe('pepperoni');
519+
});
509520
});
510521

511522
describe('disableClose option', () => {
@@ -1055,6 +1066,7 @@ class ComponentWithTemplateRef {
10551066
changeDetection: ChangeDetectionStrategy.Eager,
10561067
})
10571068
class PizzaMsg {
1069+
@Input() flavor = 'unknown';
10581070
bottomSheetRef = inject<MatBottomSheetRef<PizzaMsg>>(MatBottomSheetRef);
10591071
injector = inject(Injector);
10601072
directionality = inject(Directionality);

0 commit comments

Comments
 (0)