Skip to content

Commit 2dec29f

Browse files
committed
refactor(material/button): convert to standalone
Converts `material/button` to standalone.
1 parent 1a302fe commit 2dec29f

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed

src/material/button/button.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {createMouseEvent, dispatchEvent} from '@angular/cdk/testing/private';
88
describe('MDC-based MatButton', () => {
99
beforeEach(waitForAsync(() => {
1010
TestBed.configureTestingModule({
11-
imports: [MatButtonModule],
12-
declarations: [TestApp],
11+
imports: [MatButtonModule, TestApp],
1312
});
1413

1514
TestBed.compileComponents();
@@ -355,8 +354,7 @@ describe('MDC-based MatButton', () => {
355354
describe('MatFabDefaultOptions', () => {
356355
function configure(defaults: MatFabDefaultOptions) {
357356
TestBed.configureTestingModule({
358-
imports: [MatButtonModule],
359-
declarations: [TestApp],
357+
imports: [MatButtonModule, TestApp],
360358
providers: [{provide: MAT_FAB_DEFAULT_OPTIONS, useValue: defaults}],
361359
});
362360

@@ -396,6 +394,8 @@ describe('MatFabDefaultOptions', () => {
396394
<button mat-fab [extended]="extended" class="extended-fab-test">Extended</button>
397395
<button mat-mini-fab>Mini Fab Button</button>
398396
`,
397+
standalone: true,
398+
imports: [MatButtonModule],
399399
})
400400
class TestApp {
401401
clickCount: number = 0;

src/material/button/button.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {MAT_ANCHOR_HOST, MAT_BUTTON_HOST, MatAnchorBase, MatButtonBase} from './
4040
exportAs: 'matButton',
4141
encapsulation: ViewEncapsulation.None,
4242
changeDetection: ChangeDetectionStrategy.OnPush,
43+
standalone: true,
4344
})
4445
export class MatButton extends MatButtonBase {
4546
constructor(
@@ -70,6 +71,7 @@ export class MatButton extends MatButtonBase {
7071
styleUrls: ['button.css', 'button-high-contrast.css'],
7172
encapsulation: ViewEncapsulation.None,
7273
changeDetection: ChangeDetectionStrategy.OnPush,
74+
standalone: true,
7375
})
7476
export class MatAnchor extends MatAnchorBase {
7577
constructor(

src/material/button/fab.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const defaults = MAT_FAB_DEFAULT_OPTIONS_FACTORY();
6969
exportAs: 'matButton',
7070
encapsulation: ViewEncapsulation.None,
7171
changeDetection: ChangeDetectionStrategy.OnPush,
72+
standalone: true,
7273
})
7374
export class MatFabButton extends MatButtonBase {
7475
override _isFab = true;
@@ -101,6 +102,7 @@ export class MatFabButton extends MatButtonBase {
101102
exportAs: 'matButton',
102103
encapsulation: ViewEncapsulation.None,
103104
changeDetection: ChangeDetectionStrategy.OnPush,
105+
standalone: true,
104106
})
105107
export class MatMiniFabButton extends MatButtonBase {
106108
override _isFab = true;
@@ -137,6 +139,7 @@ export class MatMiniFabButton extends MatButtonBase {
137139
exportAs: 'matButton, matAnchor',
138140
encapsulation: ViewEncapsulation.None,
139141
changeDetection: ChangeDetectionStrategy.OnPush,
142+
standalone: true,
140143
})
141144
export class MatFabAnchor extends MatAnchor {
142145
override _isFab = true;
@@ -169,6 +172,7 @@ export class MatFabAnchor extends MatAnchor {
169172
exportAs: 'matButton, matAnchor',
170173
encapsulation: ViewEncapsulation.None,
171174
changeDetection: ChangeDetectionStrategy.OnPush,
175+
standalone: true,
172176
})
173177
export class MatMiniFabAnchor extends MatAnchor {
174178
override _isFab = true;

src/material/button/icon-button.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {MAT_ANCHOR_HOST, MAT_BUTTON_HOST, MatAnchorBase, MatButtonBase} from './
3232
exportAs: 'matButton',
3333
encapsulation: ViewEncapsulation.None,
3434
changeDetection: ChangeDetectionStrategy.OnPush,
35+
standalone: true,
3536
})
3637
export class MatIconButton extends MatButtonBase {
3738
constructor(
@@ -59,6 +60,7 @@ export class MatIconButton extends MatButtonBase {
5960
exportAs: 'matButton, matAnchor',
6061
encapsulation: ViewEncapsulation.None,
6162
changeDetection: ChangeDetectionStrategy.OnPush,
63+
standalone: true,
6264
})
6365
export class MatIconAnchor extends MatAnchorBase {
6466
constructor(

src/material/button/module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@ import {MatFabAnchor, MatFabButton, MatMiniFabAnchor, MatMiniFabButton} from './
1313
import {MatIconAnchor, MatIconButton} from './icon-button';
1414

1515
@NgModule({
16-
imports: [MatCommonModule, MatRippleModule],
17-
exports: [
16+
imports: [
17+
MatCommonModule,
18+
MatRippleModule,
1819
MatAnchor,
1920
MatButton,
2021
MatIconAnchor,
21-
MatIconButton,
2222
MatMiniFabAnchor,
2323
MatMiniFabButton,
24+
MatIconButton,
2425
MatFabAnchor,
2526
MatFabButton,
26-
MatCommonModule,
2727
],
28-
declarations: [
28+
exports: [
2929
MatAnchor,
3030
MatButton,
3131
MatIconAnchor,
32+
MatIconButton,
3233
MatMiniFabAnchor,
3334
MatMiniFabButton,
34-
MatIconButton,
3535
MatFabAnchor,
3636
MatFabButton,
37+
MatCommonModule,
3738
],
3839
})
3940
export class MatButtonModule {}

src/material/button/testing/button-harness.spec.ts

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

1616
beforeEach(async () => {
1717
await TestBed.configureTestingModule({
18-
imports: [MatButtonModule, MatIconModule, PlatformModule],
19-
declarations: [ButtonHarnessTest],
18+
imports: [MatButtonModule, MatIconModule, PlatformModule, ButtonHarnessTest],
2019
}).compileComponents();
2120

2221
fixture = TestBed.createComponent(ButtonHarnessTest);
@@ -175,6 +174,8 @@ describe('MatButtonHarness', () => {
175174
<a id="anchor-fab" mat-fab>Fab anchor</a>
176175
<a id="anchor-mini-fab" mat-mini-fab>Mini Fab anchor</a>
177176
`,
177+
standalone: true,
178+
imports: [MatButtonModule, MatIconModule, PlatformModule],
178179
})
179180
class ButtonHarnessTest {
180181
disabled = true;

tools/public_api_guard/material/button.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AfterViewInit } from '@angular/core';
88
import { ElementRef } from '@angular/core';
99
import { FocusOrigin } from '@angular/cdk/a11y';
1010
import * as i0 from '@angular/core';
11-
import * as i4 from '@angular/material/core';
11+
import * as i1 from '@angular/material/core';
1212
import { InjectionToken } from '@angular/core';
1313
import { MatRipple } from '@angular/material/core';
1414
import { MatRippleLoader } from '@angular/material/core';
@@ -28,7 +28,7 @@ export function MAT_FAB_DEFAULT_OPTIONS_FACTORY(): MatFabDefaultOptions;
2828
export class MatAnchor extends MatAnchorBase {
2929
constructor(elementRef: ElementRef, platform: Platform, ngZone: NgZone, animationMode?: string);
3030
// (undocumented)
31-
static ɵcmp: i0.ɵɵComponentDeclaration<MatAnchor, "a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
31+
static ɵcmp: i0.ɵɵComponentDeclaration<MatAnchor, "a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
3232
// (undocumented)
3333
static ɵfac: i0.ɵɵFactoryDeclaration<MatAnchor, [null, null, null, { optional: true; }]>;
3434
}
@@ -37,7 +37,7 @@ export class MatAnchor extends MatAnchorBase {
3737
export class MatButton extends MatButtonBase {
3838
constructor(elementRef: ElementRef, platform: Platform, ngZone: NgZone, animationMode?: string);
3939
// (undocumented)
40-
static ɵcmp: i0.ɵɵComponentDeclaration<MatButton, " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", ["matButton"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
40+
static ɵcmp: i0.ɵɵComponentDeclaration<MatButton, " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", ["matButton"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
4141
// (undocumented)
4242
static ɵfac: i0.ɵɵFactoryDeclaration<MatButton, [null, null, null, { optional: true; }]>;
4343
}
@@ -49,7 +49,7 @@ export class MatButtonModule {
4949
// (undocumented)
5050
static ɵinj: i0.ɵɵInjectorDeclaration<MatButtonModule>;
5151
// (undocumented)
52-
static ɵmod: i0.ɵɵNgModuleDeclaration<MatButtonModule, [typeof i1.MatAnchor, typeof i1.MatButton, typeof i2.MatIconAnchor, typeof i3.MatMiniFabAnchor, typeof i3.MatMiniFabButton, typeof i2.MatIconButton, typeof i3.MatFabAnchor, typeof i3.MatFabButton], [typeof i4.MatCommonModule, typeof i4.MatRippleModule], [typeof i1.MatAnchor, typeof i1.MatButton, typeof i2.MatIconAnchor, typeof i2.MatIconButton, typeof i3.MatMiniFabAnchor, typeof i3.MatMiniFabButton, typeof i3.MatFabAnchor, typeof i3.MatFabButton, typeof i4.MatCommonModule]>;
52+
static ɵmod: i0.ɵɵNgModuleDeclaration<MatButtonModule, never, [typeof i1.MatCommonModule, typeof i1.MatRippleModule, typeof i2.MatAnchor, typeof i2.MatButton, typeof i3.MatIconAnchor, typeof i4.MatMiniFabAnchor, typeof i4.MatMiniFabButton, typeof i3.MatIconButton, typeof i4.MatFabAnchor, typeof i4.MatFabButton], [typeof i2.MatAnchor, typeof i2.MatButton, typeof i3.MatIconAnchor, typeof i3.MatIconButton, typeof i4.MatMiniFabAnchor, typeof i4.MatMiniFabButton, typeof i4.MatFabAnchor, typeof i4.MatFabButton, typeof i1.MatCommonModule]>;
5353
}
5454

5555
// @public
@@ -62,7 +62,7 @@ export class MatFabAnchor extends MatAnchor {
6262
// (undocumented)
6363
static ngAcceptInputType_extended: unknown;
6464
// (undocumented)
65-
static ɵcmp: i0.ɵɵComponentDeclaration<MatFabAnchor, "a[mat-fab]", ["matButton", "matAnchor"], { "extended": { "alias": "extended"; "required": false; }; }, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
65+
static ɵcmp: i0.ɵɵComponentDeclaration<MatFabAnchor, "a[mat-fab]", ["matButton", "matAnchor"], { "extended": { "alias": "extended"; "required": false; }; }, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
6666
// (undocumented)
6767
static ɵfac: i0.ɵɵFactoryDeclaration<MatFabAnchor, [null, null, null, { optional: true; }, { optional: true; }]>;
6868
}
@@ -77,7 +77,7 @@ export class MatFabButton extends MatButtonBase {
7777
// (undocumented)
7878
static ngAcceptInputType_extended: unknown;
7979
// (undocumented)
80-
static ɵcmp: i0.ɵɵComponentDeclaration<MatFabButton, "button[mat-fab]", ["matButton"], { "extended": { "alias": "extended"; "required": false; }; }, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
80+
static ɵcmp: i0.ɵɵComponentDeclaration<MatFabButton, "button[mat-fab]", ["matButton"], { "extended": { "alias": "extended"; "required": false; }; }, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
8181
// (undocumented)
8282
static ɵfac: i0.ɵɵFactoryDeclaration<MatFabButton, [null, null, null, { optional: true; }, { optional: true; }]>;
8383
}
@@ -92,7 +92,7 @@ export interface MatFabDefaultOptions {
9292
export class MatIconAnchor extends MatAnchorBase {
9393
constructor(elementRef: ElementRef, platform: Platform, ngZone: NgZone, animationMode?: string);
9494
// (undocumented)
95-
static ɵcmp: i0.ɵɵComponentDeclaration<MatIconAnchor, "a[mat-icon-button]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
95+
static ɵcmp: i0.ɵɵComponentDeclaration<MatIconAnchor, "a[mat-icon-button]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
9696
// (undocumented)
9797
static ɵfac: i0.ɵɵFactoryDeclaration<MatIconAnchor, [null, null, null, { optional: true; }]>;
9898
}
@@ -101,7 +101,7 @@ export class MatIconAnchor extends MatAnchorBase {
101101
export class MatIconButton extends MatButtonBase {
102102
constructor(elementRef: ElementRef, platform: Platform, ngZone: NgZone, animationMode?: string);
103103
// (undocumented)
104-
static ɵcmp: i0.ɵɵComponentDeclaration<MatIconButton, "button[mat-icon-button]", ["matButton"], {}, {}, never, ["*"], false, never>;
104+
static ɵcmp: i0.ɵɵComponentDeclaration<MatIconButton, "button[mat-icon-button]", ["matButton"], {}, {}, never, ["*"], true, never>;
105105
// (undocumented)
106106
static ɵfac: i0.ɵɵFactoryDeclaration<MatIconButton, [null, null, null, { optional: true; }]>;
107107
}
@@ -112,7 +112,7 @@ export class MatMiniFabAnchor extends MatAnchor {
112112
// (undocumented)
113113
_isFab: boolean;
114114
// (undocumented)
115-
static ɵcmp: i0.ɵɵComponentDeclaration<MatMiniFabAnchor, "a[mat-mini-fab]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
115+
static ɵcmp: i0.ɵɵComponentDeclaration<MatMiniFabAnchor, "a[mat-mini-fab]", ["matButton", "matAnchor"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
116116
// (undocumented)
117117
static ɵfac: i0.ɵɵFactoryDeclaration<MatMiniFabAnchor, [null, null, null, { optional: true; }, { optional: true; }]>;
118118
}
@@ -123,7 +123,7 @@ export class MatMiniFabButton extends MatButtonBase {
123123
// (undocumented)
124124
_isFab: boolean;
125125
// (undocumented)
126-
static ɵcmp: i0.ɵɵComponentDeclaration<MatMiniFabButton, "button[mat-mini-fab]", ["matButton"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], false, never>;
126+
static ɵcmp: i0.ɵɵComponentDeclaration<MatMiniFabButton, "button[mat-mini-fab]", ["matButton"], {}, {}, never, [".material-icons:not([iconPositionEnd]), mat-icon:not([iconPositionEnd]), [matButtonIcon]:not([iconPositionEnd])", "*", ".material-icons[iconPositionEnd], mat-icon[iconPositionEnd], [matButtonIcon][iconPositionEnd]"], true, never>;
127127
// (undocumented)
128128
static ɵfac: i0.ɵɵFactoryDeclaration<MatMiniFabButton, [null, null, null, { optional: true; }, { optional: true; }]>;
129129
}

0 commit comments

Comments
 (0)