Skip to content

Commit

Permalink
refactor(multiple): switch remaining directives to standalone.
Browse files Browse the repository at this point in the history
Switches all remaining directives to standalone and updates the linter to enforce that all directives and components are standalone.
  • Loading branch information
crisbeto committed Nov 29, 2023
1 parent 187a7b8 commit eab9d7d
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/cdk/menu/menu-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let nextId = 0;
'(focusin)': 'menuStack.setHasFocus(true)',
'(focusout)': 'menuStack.setHasFocus(false)',
},
standalone: true,
})
export abstract class CdkMenuBase
extends CdkMenuGroup
Expand Down
1 change: 1 addition & 0 deletions src/cdk/menu/menu-item-selectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {CdkMenuItem} from './menu-item';
'[attr.aria-checked]': '!!checked',
'[attr.aria-disabled]': 'disabled || null',
},
standalone: true,
})
export abstract class CdkMenuItemSelectable extends CdkMenuItem {
/** Whether the element is checked */
Expand Down
1 change: 1 addition & 0 deletions src/cdk/menu/menu-trigger-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const MENU_TRIGGER = new InjectionToken<CdkMenuTriggerBase>('cdk-menu-tri
'[attr.aria-controls]': 'childMenu?.id',
'[attr.data-cdk-menu-stack-id]': 'menuStack.id',
},
standalone: true,
})
export abstract class CdkMenuTriggerBase implements OnDestroy {
/** The DI injector for this component. */
Expand Down
1 change: 0 additions & 1 deletion src/cdk/testing/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

export * from './test-components-module';
export * from './test-main-component';
export * from './test-sub-component';
export * from './test-shadow-boundary';
23 changes: 0 additions & 23 deletions src/cdk/testing/tests/test-components-module.ts

This file was deleted.

11 changes: 9 additions & 2 deletions src/cdk/testing/tests/test-main-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {ENTER} from '@angular/cdk/keycodes';
import {_supportsShadowDom} from '@angular/cdk/platform';
import {FormControl} from '@angular/forms';
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Expand All @@ -19,12 +19,16 @@ import {
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {TestShadowBoundary} from './test-shadow-boundary';
import {TestSubComponent} from './test-sub-component';

@Component({
selector: 'test-main',
templateUrl: 'test-main-component.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [TestShadowBoundary, TestSubComponent, FormsModule, ReactiveFormsModule],
})
export class TestMainComponent implements OnDestroy {
username: string;
Expand Down Expand Up @@ -54,7 +58,10 @@ export class TestMainComponent implements OnDestroy {

private _fakeOverlayElement: HTMLElement;

constructor(private _cdr: ChangeDetectorRef, private _zone: NgZone) {
constructor(
private _cdr: ChangeDetectorRef,
private _zone: NgZone,
) {
this.username = 'Yi';
this.counter = 0;
this.asyncCounter = 0;
Expand Down
21 changes: 12 additions & 9 deletions src/cdk/testing/tests/test-shadow-boundary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';

@Component({
selector: 'test-shadow-boundary',
template: `
<div class="in-the-shadows">Shadow 1</div>
<test-sub-shadow-boundary></test-sub-shadow-boundary>
`,
selector: 'test-sub-shadow-boundary',
template: '<div class="in-the-shadows">Shadow 2</div>',
changeDetection: ChangeDetectionStrategy.OnPush,
// tslint:disable-next-line:validate-decorators
encapsulation: ViewEncapsulation.ShadowDom,
standalone: true,
})
export class TestShadowBoundary {}
export class TestSubShadowBoundary {}

@Component({
selector: 'test-sub-shadow-boundary',
template: '<div class="in-the-shadows">Shadow 2</div>',
selector: 'test-shadow-boundary',
template: `
<div class="in-the-shadows">Shadow 1</div>
<test-sub-shadow-boundary></test-sub-shadow-boundary>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
// tslint:disable-next-line:validate-decorators
encapsulation: ViewEncapsulation.ShadowDom,
standalone: true,
imports: [TestSubShadowBoundary],
})
export class TestSubShadowBoundary {}
export class TestShadowBoundary {}
1 change: 1 addition & 0 deletions src/cdk/testing/tests/test-sub-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {ChangeDetectionStrategy, Component, Input, ViewEncapsulation} from '@ang
</ul>`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class TestSubComponent {
@Input() title: string;
Expand Down
11 changes: 5 additions & 6 deletions src/cdk/testing/tests/testbed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {querySelectorAll as piercingQuerySelectorAll} from 'kagekiri';
import {crossEnvironmentSpecs} from './cross-environment.spec';
import {FakeOverlayHarness} from './harnesses/fake-overlay-harness';
import {MainComponentHarness} from './harnesses/main-component-harness';
import {TestComponentsModule} from './test-components-module';
import {TestMainComponent} from './test-main-component';

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

beforeEach(async () => {
await TestBed.configureTestingModule({imports: [TestComponentsModule]}).compileComponents();
beforeEach(() => {
fixture = TestBed.createComponent(TestMainComponent);
});

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

it('should be able to load harness through document root loader', async () => {
const documentRootHarnesses = await TestbedHarnessEnvironment.documentRootLoader(
fixture,
).getAllHarnesses(FakeOverlayHarness);
const documentRootHarnesses =
await TestbedHarnessEnvironment.documentRootLoader(fixture).getAllHarnesses(
FakeOverlayHarness,
);
const fixtureHarnesses = await loader.getAllHarnesses(FakeOverlayHarness);
expect(fixtureHarnesses.length).toBe(0);
expect(documentRootHarnesses.length).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions src/e2e-app/components/component-harness-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
import {TestComponentsModule} from '@angular/cdk/testing/tests';
import {TestMainComponent} from '@angular/cdk/testing/tests';

@Component({
selector: 'component-harness-e2e',
template: `<test-main></test-main>`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [TestComponentsModule],
imports: [TestMainComponent],
})
export class ComponentHarnessE2e {}
2 changes: 2 additions & 0 deletions src/material/list/list-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {MAT_LIST_CONFIG} from './tokens';
host: {
'[attr.aria-disabled]': 'disabled',
},
standalone: true,
})
/** @docs-private */
export abstract class MatListBase {
Expand Down Expand Up @@ -79,6 +80,7 @@ export abstract class MatListBase {
'[attr.aria-disabled]': 'disabled',
'[attr.disabled]': '(_isButtonElement && disabled) || null',
},
standalone: true,
})
/** @docs-private */
export abstract class MatListItemBase implements AfterViewInit, OnDestroy, RippleTarget {
Expand Down
1 change: 1 addition & 0 deletions src/material/list/list-item-sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class MatListItemMeta {}
'[class.mdc-list-item__start]': '_isAlignedAtStart()',
'[class.mdc-list-item__end]': '!_isAlignedAtStart()',
},
standalone: true,
})
export class _MatListItemGraphicBase {
constructor(@Optional() @Inject(LIST_OPTION) public _listOption: ListOption) {}
Expand Down
6 changes: 3 additions & 3 deletions tools/public_api_guard/cdk/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export abstract class CdkMenuBase extends CdkMenuGroup implements Menu, AfterCon
protected pointerTracker?: PointerFocusTracker<CdkMenuItem>;
protected triggerItem?: CdkMenuItem;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBase, never, never, { "id": { "alias": "id"; "required": false; }; }, {}, ["items"], never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBase, never, never, { "id": { "alias": "id"; "required": false; }; }, {}, ["items"], never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuBase, never>;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ export abstract class CdkMenuItemSelectable extends CdkMenuItem {
// (undocumented)
static ngAcceptInputType_checked: unknown;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemSelectable, never, never, { "checked": { "alias": "cdkMenuItemChecked"; "required": false; }; }, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemSelectable, never, never, { "checked": { "alias": "cdkMenuItemChecked"; "required": false; }; }, {}, never, never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItemSelectable, never>;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ export abstract class CdkMenuTriggerBase implements OnDestroy {
protected readonly stopOutsideClicksListener: Observable<void>;
protected readonly viewContainerRef: ViewContainerRef;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTriggerBase, never, never, {}, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTriggerBase, never, never, {}, {}, never, never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuTriggerBase, never>;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class _MatListItemGraphicBase {
// (undocumented)
_listOption: ListOption;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatListItemGraphicBase, never, never, {}, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatListItemGraphicBase, never, never, {}, {}, never, never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<_MatListItemGraphicBase, [{ optional: true; }]>;
}
Expand Down
6 changes: 4 additions & 2 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@
"!styles": ".*",
"!moduleId": ".*",
"changeDetection": "\\.OnPush$",
"encapsulation": "\\.None$"
"encapsulation": "\\.None$",
"standalone": "^true$"
}
},
"Directive": {
"argument": 0,
"properties": {
"!host": "\\[class\\]"
"!host": "\\[class\\]",
"standalone": "^true$"
}
},
"NgModule": {
Expand Down

0 comments on commit eab9d7d

Please sign in to comment.