Skip to content

Commit d38adb9

Browse files
authored
refactor(multiple): switch remaining directives to standalone (#28202)
Switches all remaining directives to standalone and updates the linter to enforce that all directives and components are standalone.
1 parent 807157d commit d38adb9

File tree

15 files changed

+43
-49
lines changed

15 files changed

+43
-49
lines changed

src/cdk/menu/menu-base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let nextId = 0;
4747
'(focusin)': 'menuStack.setHasFocus(true)',
4848
'(focusout)': 'menuStack.setHasFocus(false)',
4949
},
50+
standalone: true,
5051
})
5152
export abstract class CdkMenuBase
5253
extends CdkMenuGroup

src/cdk/menu/menu-item-selectable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {CdkMenuItem} from './menu-item';
1515
'[attr.aria-checked]': '!!checked',
1616
'[attr.aria-disabled]': 'disabled || null',
1717
},
18+
standalone: true,
1819
})
1920
export abstract class CdkMenuItemSelectable extends CdkMenuItem {
2021
/** Whether the element is checked */

src/cdk/menu/menu-trigger-base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const MENU_TRIGGER = new InjectionToken<CdkMenuTriggerBase>('cdk-menu-tri
3434
'[attr.aria-controls]': 'childMenu?.id',
3535
'[attr.data-cdk-menu-stack-id]': 'menuStack.id',
3636
},
37+
standalone: true,
3738
})
3839
export abstract class CdkMenuTriggerBase implements OnDestroy {
3940
/** The DI injector for this component. */

src/cdk/testing/tests/index.ts

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

9-
export * from './test-components-module';
109
export * from './test-main-component';
1110
export * from './test-sub-component';
1211
export * from './test-shadow-boundary';

src/cdk/testing/tests/test-components-module.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/cdk/testing/tests/test-main-component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ENTER} from '@angular/cdk/keycodes';
1010
import {_supportsShadowDom} from '@angular/cdk/platform';
11-
import {FormControl} from '@angular/forms';
11+
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
1212
import {
1313
ChangeDetectionStrategy,
1414
ChangeDetectorRef,
@@ -19,12 +19,16 @@ import {
1919
ViewChild,
2020
ViewEncapsulation,
2121
} from '@angular/core';
22+
import {TestShadowBoundary} from './test-shadow-boundary';
23+
import {TestSubComponent} from './test-sub-component';
2224

2325
@Component({
2426
selector: 'test-main',
2527
templateUrl: 'test-main-component.html',
2628
encapsulation: ViewEncapsulation.None,
2729
changeDetection: ChangeDetectionStrategy.OnPush,
30+
standalone: true,
31+
imports: [TestShadowBoundary, TestSubComponent, FormsModule, ReactiveFormsModule],
2832
})
2933
export class TestMainComponent implements OnDestroy {
3034
username: string;
@@ -54,7 +58,10 @@ export class TestMainComponent implements OnDestroy {
5458

5559
private _fakeOverlayElement: HTMLElement;
5660

57-
constructor(private _cdr: ChangeDetectorRef, private _zone: NgZone) {
61+
constructor(
62+
private _cdr: ChangeDetectorRef,
63+
private _zone: NgZone,
64+
) {
5865
this.username = 'Yi';
5966
this.counter = 0;
6067
this.asyncCounter = 0;

src/cdk/testing/tests/test-shadow-boundary.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@
99
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
1010

1111
@Component({
12-
selector: 'test-shadow-boundary',
13-
template: `
14-
<div class="in-the-shadows">Shadow 1</div>
15-
<test-sub-shadow-boundary></test-sub-shadow-boundary>
16-
`,
12+
selector: 'test-sub-shadow-boundary',
13+
template: '<div class="in-the-shadows">Shadow 2</div>',
1714
changeDetection: ChangeDetectionStrategy.OnPush,
1815
// tslint:disable-next-line:validate-decorators
1916
encapsulation: ViewEncapsulation.ShadowDom,
17+
standalone: true,
2018
})
21-
export class TestShadowBoundary {}
19+
export class TestSubShadowBoundary {}
2220

2321
@Component({
24-
selector: 'test-sub-shadow-boundary',
25-
template: '<div class="in-the-shadows">Shadow 2</div>',
22+
selector: 'test-shadow-boundary',
23+
template: `
24+
<div class="in-the-shadows">Shadow 1</div>
25+
<test-sub-shadow-boundary></test-sub-shadow-boundary>
26+
`,
2627
changeDetection: ChangeDetectionStrategy.OnPush,
2728
// tslint:disable-next-line:validate-decorators
2829
encapsulation: ViewEncapsulation.ShadowDom,
30+
standalone: true,
31+
imports: [TestSubShadowBoundary],
2932
})
30-
export class TestSubShadowBoundary {}
33+
export class TestShadowBoundary {}

src/cdk/testing/tests/test-sub-component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {ChangeDetectionStrategy, Component, Input, ViewEncapsulation} from '@ang
1919
</ul>`,
2020
encapsulation: ViewEncapsulation.None,
2121
changeDetection: ChangeDetectionStrategy.OnPush,
22+
standalone: true,
2223
})
2324
export class TestSubComponent {
2425
@Input() title: string;

src/cdk/testing/tests/testbed.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import {querySelectorAll as piercingQuerySelectorAll} from 'kagekiri';
66
import {crossEnvironmentSpecs} from './cross-environment.spec';
77
import {FakeOverlayHarness} from './harnesses/fake-overlay-harness';
88
import {MainComponentHarness} from './harnesses/main-component-harness';
9-
import {TestComponentsModule} from './test-components-module';
109
import {TestMainComponent} from './test-main-component';
1110

1211
describe('TestbedHarnessEnvironment', () => {
1312
let fixture: ComponentFixture<{}>;
1413

15-
beforeEach(async () => {
16-
await TestBed.configureTestingModule({imports: [TestComponentsModule]}).compileComponents();
14+
beforeEach(() => {
1715
fixture = TestBed.createComponent(TestMainComponent);
1816
});
1917

@@ -38,9 +36,10 @@ describe('TestbedHarnessEnvironment', () => {
3836
});
3937

4038
it('should be able to load harness through document root loader', async () => {
41-
const documentRootHarnesses = await TestbedHarnessEnvironment.documentRootLoader(
42-
fixture,
43-
).getAllHarnesses(FakeOverlayHarness);
39+
const documentRootHarnesses =
40+
await TestbedHarnessEnvironment.documentRootLoader(fixture).getAllHarnesses(
41+
FakeOverlayHarness,
42+
);
4443
const fixtureHarnesses = await loader.getAllHarnesses(FakeOverlayHarness);
4544
expect(fixtureHarnesses.length).toBe(0);
4645
expect(documentRootHarnesses.length).toBe(1);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
2-
import {TestComponentsModule} from '@angular/cdk/testing/tests';
2+
import {TestMainComponent} from '@angular/cdk/testing/tests';
33

44
@Component({
55
selector: 'component-harness-e2e',
66
template: `<test-main></test-main>`,
77
encapsulation: ViewEncapsulation.None,
88
changeDetection: ChangeDetectionStrategy.OnPush,
99
standalone: true,
10-
imports: [TestComponentsModule],
10+
imports: [TestMainComponent],
1111
})
1212
export class ComponentHarnessE2e {}

src/material/list/list-base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {MAT_LIST_CONFIG} from './tokens';
4242
host: {
4343
'[attr.aria-disabled]': 'disabled',
4444
},
45+
standalone: true,
4546
})
4647
/** @docs-private */
4748
export abstract class MatListBase {
@@ -79,6 +80,7 @@ export abstract class MatListBase {
7980
'[attr.aria-disabled]': 'disabled',
8081
'[attr.disabled]': '(_isButtonElement && disabled) || null',
8182
},
83+
standalone: true,
8284
})
8385
/** @docs-private */
8486
export abstract class MatListItemBase implements AfterViewInit, OnDestroy, RippleTarget {

src/material/list/list-item-sections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class MatListItemMeta {}
6969
'[class.mdc-list-item__start]': '_isAlignedAtStart()',
7070
'[class.mdc-list-item__end]': '!_isAlignedAtStart()',
7171
},
72+
standalone: true,
7273
})
7374
export class _MatListItemGraphicBase {
7475
constructor(@Optional() @Inject(LIST_OPTION) public _listOption: ListOption) {}

tools/public_api_guard/cdk/menu.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export abstract class CdkMenuBase extends CdkMenuGroup implements Menu, AfterCon
101101
protected pointerTracker?: PointerFocusTracker<CdkMenuItem>;
102102
protected triggerItem?: CdkMenuItem;
103103
// (undocumented)
104-
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBase, never, never, { "id": { "alias": "id"; "required": false; }; }, {}, ["items"], never, false, never>;
104+
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBase, never, never, { "id": { "alias": "id"; "required": false; }; }, {}, ["items"], never, true, never>;
105105
// (undocumented)
106106
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuBase, never>;
107107
}
@@ -183,7 +183,7 @@ export abstract class CdkMenuItemSelectable extends CdkMenuItem {
183183
// (undocumented)
184184
static ngAcceptInputType_checked: unknown;
185185
// (undocumented)
186-
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemSelectable, never, never, { "checked": { "alias": "cdkMenuItemChecked"; "required": false; }; }, {}, never, never, false, never>;
186+
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemSelectable, never, never, { "checked": { "alias": "cdkMenuItemChecked"; "required": false; }; }, {}, never, never, true, never>;
187187
// (undocumented)
188188
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItemSelectable, never>;
189189
}
@@ -235,7 +235,7 @@ export abstract class CdkMenuTriggerBase implements OnDestroy {
235235
protected readonly stopOutsideClicksListener: Observable<void>;
236236
protected readonly viewContainerRef: ViewContainerRef;
237237
// (undocumented)
238-
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTriggerBase, never, never, {}, {}, never, never, false, never>;
238+
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTriggerBase, never, never, {}, {}, never, never, true, never>;
239239
// (undocumented)
240240
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuTriggerBase, never>;
241241
}

tools/public_api_guard/material/list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class _MatListItemGraphicBase {
104104
// (undocumented)
105105
_listOption: ListOption;
106106
// (undocumented)
107-
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatListItemGraphicBase, never, never, {}, {}, never, never, false, never>;
107+
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatListItemGraphicBase, never, never, {}, {}, never, never, true, never>;
108108
// (undocumented)
109109
static ɵfac: i0.ɵɵFactoryDeclaration<_MatListItemGraphicBase, [{ optional: true; }]>;
110110
}

tslint.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@
9797
"!styles": ".*",
9898
"!moduleId": ".*",
9999
"changeDetection": "\\.OnPush$",
100-
"encapsulation": "\\.None$"
100+
"encapsulation": "\\.None$",
101+
"standalone": "^true$"
101102
}
102103
},
103104
"Directive": {
104105
"argument": 0,
105106
"properties": {
106-
"!host": "\\[class\\]"
107+
"!host": "\\[class\\]",
108+
"standalone": "^true$"
107109
}
108110
},
109111
"NgModule": {

0 commit comments

Comments
 (0)