Skip to content

Commit 1a302fe

Browse files
committed
refactor(material/bottom-sheet): convert to standalone
Converts `material/bottom-sheet` to standalone.
1 parent b4c9900 commit 1a302fe

File tree

6 files changed

+56
-23
lines changed

6 files changed

+56
-23
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from '@angular/core';
2727
import {Subscription} from 'rxjs';
2828
import {matBottomSheetAnimations} from './bottom-sheet-animations';
29+
import {CdkPortalOutlet} from '@angular/cdk/portal';
2930

3031
/**
3132
* Internal component that wraps user-provided bottom sheet content.
@@ -52,6 +53,8 @@ import {matBottomSheetAnimations} from './bottom-sheet-animations';
5253
'(@state.start)': '_onAnimationStart($event)',
5354
'(@state.done)': '_onAnimationDone($event)',
5455
},
56+
standalone: true,
57+
imports: [CdkPortalOutlet],
5558
})
5659
export class MatBottomSheetContainer extends CdkDialogContainer implements OnDestroy {
5760
private _breakpointSubscription: Subscription;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {PortalModule} from '@angular/cdk/portal';
1111
import {NgModule} from '@angular/core';
1212
import {MatCommonModule} from '@angular/material/core';
1313
import {MatBottomSheetContainer} from './bottom-sheet-container';
14+
import {MatBottomSheet} from './bottom-sheet';
1415

1516
@NgModule({
16-
imports: [DialogModule, MatCommonModule, PortalModule],
17+
imports: [DialogModule, MatCommonModule, PortalModule, MatBottomSheetContainer],
1718
exports: [MatBottomSheetContainer, MatCommonModule],
18-
declarations: [MatBottomSheetContainer],
19+
providers: [MatBottomSheet],
1920
})
2021
export class MatBottomSheetModule {}

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

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import {A, ESCAPE} from '@angular/cdk/keycodes';
33
import {OverlayContainer, ScrollStrategy} from '@angular/cdk/overlay';
44
import {_supportsShadowDom} from '@angular/cdk/platform';
55
import {ViewportRuler} from '@angular/cdk/scrolling';
6-
import {dispatchKeyboardEvent, createKeyboardEvent, dispatchEvent} from '../../cdk/testing/private';
6+
import {
7+
dispatchKeyboardEvent,
8+
createKeyboardEvent,
9+
dispatchEvent,
10+
} from '@angular/cdk/testing/private';
711
import {Location} from '@angular/common';
812
import {SpyLocation} from '@angular/common/testing';
913
import {
@@ -45,8 +49,9 @@ describe('MatBottomSheet', () => {
4549

4650
beforeEach(fakeAsync(() => {
4751
TestBed.configureTestingModule({
48-
imports: [MatBottomSheetModule, NoopAnimationsModule],
49-
declarations: [
52+
imports: [
53+
MatBottomSheetModule,
54+
NoopAnimationsModule,
5055
ComponentWithChildViewContainer,
5156
ComponentWithTemplateRef,
5257
ContentElementDialog,
@@ -857,8 +862,7 @@ describe('MatBottomSheet with parent MatBottomSheet', () => {
857862

858863
beforeEach(fakeAsync(() => {
859864
TestBed.configureTestingModule({
860-
imports: [MatBottomSheetModule, NoopAnimationsModule],
861-
declarations: [ComponentThatProvidesMatBottomSheet],
865+
imports: [MatBottomSheetModule, NoopAnimationsModule, ComponentThatProvidesMatBottomSheet],
862866
}).compileComponents();
863867
}));
864868

@@ -943,8 +947,12 @@ describe('MatBottomSheet with default options', () => {
943947
};
944948

945949
TestBed.configureTestingModule({
946-
imports: [MatBottomSheetModule, NoopAnimationsModule],
947-
declarations: [ComponentWithChildViewContainer, DirectiveWithViewContainer],
950+
imports: [
951+
MatBottomSheetModule,
952+
NoopAnimationsModule,
953+
ComponentWithChildViewContainer,
954+
DirectiveWithViewContainer,
955+
],
948956
providers: [{provide: MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, useValue: defaultConfig}],
949957
});
950958

@@ -998,12 +1006,19 @@ describe('MatBottomSheet with default options', () => {
9981006
}));
9991007
});
10001008

1001-
@Directive({selector: 'dir-with-view-container'})
1009+
@Directive({
1010+
selector: 'dir-with-view-container',
1011+
standalone: true,
1012+
})
10021013
class DirectiveWithViewContainer {
10031014
constructor(public viewContainerRef: ViewContainerRef) {}
10041015
}
10051016

1006-
@Component({template: `<dir-with-view-container></dir-with-view-container>`})
1017+
@Component({
1018+
template: `<dir-with-view-container></dir-with-view-container>`,
1019+
standalone: true,
1020+
imports: [DirectiveWithViewContainer],
1021+
})
10071022
class ComponentWithChildViewContainer {
10081023
@ViewChild(DirectiveWithViewContainer) childWithViewContainer: DirectiveWithViewContainer;
10091024

@@ -1016,6 +1031,7 @@ class ComponentWithChildViewContainer {
10161031
selector: 'arbitrary-component-with-template-ref',
10171032
template: `<ng-template let-data let-bottomSheetRef="bottomSheetRef">
10181033
Cheese {{localValue}} {{data?.value}}{{setRef(bottomSheetRef)}}</ng-template>`,
1034+
standalone: true,
10191035
})
10201036
class ComponentWithTemplateRef {
10211037
localValue: string;
@@ -1029,7 +1045,10 @@ class ComponentWithTemplateRef {
10291045
}
10301046
}
10311047

1032-
@Component({template: '<p>Pizza</p> <input> <button>Close</button>'})
1048+
@Component({
1049+
template: '<p>Pizza</p> <input> <button>Close</button>',
1050+
standalone: true,
1051+
})
10331052
class PizzaMsg {
10341053
constructor(
10351054
public bottomSheetRef: MatBottomSheetRef<PizzaMsg>,
@@ -1038,32 +1057,42 @@ class PizzaMsg {
10381057
) {}
10391058
}
10401059

1041-
@Component({template: '<p>Taco</p>'})
1060+
@Component({
1061+
template: '<p>Taco</p>',
1062+
standalone: true,
1063+
})
10421064
class TacoMsg {}
10431065

10441066
@Component({
10451067
template: `
10461068
<h1>This is the title</h1>
10471069
<p>This is the paragraph</p>
10481070
`,
1071+
standalone: true,
10491072
})
10501073
class ContentElementDialog {}
10511074

10521075
@Component({
10531076
template: '',
10541077
providers: [MatBottomSheet],
1078+
standalone: true,
1079+
imports: [MatBottomSheetModule],
10551080
})
10561081
class ComponentThatProvidesMatBottomSheet {
10571082
constructor(public bottomSheet: MatBottomSheet) {}
10581083
}
10591084

1060-
@Component({template: ''})
1085+
@Component({
1086+
template: '',
1087+
standalone: true,
1088+
})
10611089
class BottomSheetWithInjectedData {
10621090
constructor(@Inject(MAT_BOTTOM_SHEET_DATA) public data: any) {}
10631091
}
10641092

10651093
@Component({
10661094
template: `<button>I'm a button</button>`,
10671095
encapsulation: ViewEncapsulation.ShadowDom,
1096+
standalone: true,
10681097
})
10691098
class ShadowDomComponent {}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from '@angular/core';
2222
import {MAT_BOTTOM_SHEET_DATA, MatBottomSheetConfig} from './bottom-sheet-config';
2323
import {MatBottomSheetContainer} from './bottom-sheet-container';
24-
import {MatBottomSheetModule} from './bottom-sheet-module';
2524
import {MatBottomSheetRef} from './bottom-sheet-ref';
2625

2726
/** Injection token that can be used to specify default bottom sheet options. */
@@ -32,7 +31,7 @@ export const MAT_BOTTOM_SHEET_DEFAULT_OPTIONS = new InjectionToken<MatBottomShee
3231
/**
3332
* Service to trigger Material Design bottom sheets.
3433
*/
35-
@Injectable({providedIn: MatBottomSheetModule})
34+
@Injectable({providedIn: 'root'})
3635
export class MatBottomSheet implements OnDestroy {
3736
private _bottomSheetRefAtThisLevel: MatBottomSheetRef<any> | null = null;
3837
private _dialog: Dialog;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ describe('MatBottomSheetHarness', () => {
1616

1717
beforeEach(async () => {
1818
await TestBed.configureTestingModule({
19-
imports: [MatBottomSheetModule, NoopAnimationsModule],
20-
declarations: [BottomSheetHarnessTest],
19+
imports: [MatBottomSheetModule, NoopAnimationsModule, BottomSheetHarnessTest],
2120
}).compileComponents();
2221

2322
fixture = TestBed.createComponent(BottomSheetHarnessTest);
@@ -55,6 +54,8 @@ describe('MatBottomSheetHarness', () => {
5554
Hello from the bottom sheet!
5655
</ng-template>
5756
`,
57+
standalone: true,
58+
imports: [MatBottomSheetModule],
5859
})
5960
class BottomSheetHarnessTest {
6061
@ViewChild(TemplateRef) template: TemplateRef<any>;

tools/public_api_guard/material/bottom-sheet.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import { EventEmitter } from '@angular/core';
1919
import { FocusMonitor } from '@angular/cdk/a11y';
2020
import { FocusTrapFactory } from '@angular/cdk/a11y';
2121
import * as i0 from '@angular/core';
22-
import * as i2 from '@angular/cdk/dialog';
23-
import * as i3 from '@angular/material/core';
24-
import * as i4 from '@angular/cdk/portal';
22+
import * as i1 from '@angular/cdk/dialog';
23+
import * as i2 from '@angular/material/core';
24+
import * as i3 from '@angular/cdk/portal';
2525
import { InjectionToken } from '@angular/core';
2626
import { Injector } from '@angular/core';
2727
import { InteractivityChecker } from '@angular/cdk/a11y';
@@ -97,7 +97,7 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
9797
// (undocumented)
9898
_onAnimationStart(event: AnimationEvent_2): void;
9999
// (undocumented)
100-
static ɵcmp: i0.ɵɵComponentDeclaration<MatBottomSheetContainer, "mat-bottom-sheet-container", never, {}, {}, never, never, false, never>;
100+
static ɵcmp: i0.ɵɵComponentDeclaration<MatBottomSheetContainer, "mat-bottom-sheet-container", never, {}, {}, never, never, true, never>;
101101
// (undocumented)
102102
static ɵfac: i0.ɵɵFactoryDeclaration<MatBottomSheetContainer, [null, null, { optional: true; }, null, null, null, null, null, null, null]>;
103103
}
@@ -109,7 +109,7 @@ export class MatBottomSheetModule {
109109
// (undocumented)
110110
static ɵinj: i0.ɵɵInjectorDeclaration<MatBottomSheetModule>;
111111
// (undocumented)
112-
static ɵmod: i0.ɵɵNgModuleDeclaration<MatBottomSheetModule, [typeof i1.MatBottomSheetContainer], [typeof i2.DialogModule, typeof i3.MatCommonModule, typeof i4.PortalModule], [typeof i1.MatBottomSheetContainer, typeof i3.MatCommonModule]>;
112+
static ɵmod: i0.ɵɵNgModuleDeclaration<MatBottomSheetModule, never, [typeof i1.DialogModule, typeof i2.MatCommonModule, typeof i3.PortalModule, typeof i4.MatBottomSheetContainer], [typeof i4.MatBottomSheetContainer, typeof i2.MatCommonModule]>;
113113
}
114114

115115
// @public

0 commit comments

Comments
 (0)