Skip to content

Commit abd94f8

Browse files
committed
refactor(material/radio): convert to standalone
Converts `material/radio` to standalone.
1 parent 36b4f18 commit abd94f8

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

src/material/radio/module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1212
import {MatRadioButton, MatRadioGroup} from './radio';
1313

1414
@NgModule({
15-
imports: [MatCommonModule, CommonModule, MatRippleModule],
15+
imports: [MatCommonModule, CommonModule, MatRippleModule, MatRadioGroup, MatRadioButton],
1616
exports: [MatCommonModule, MatRadioGroup, MatRadioButton],
17-
declarations: [MatRadioGroup, MatRadioButton],
1817
})
1918
export class MatRadioModule {}

src/material/radio/radio.spec.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/f
33
import {Component, DebugElement, ViewChild} from '@angular/core';
44
import {CommonModule} from '@angular/common';
55
import {By} from '@angular/platform-browser';
6-
import {dispatchFakeEvent} from '../../cdk/testing/private';
6+
import {dispatchFakeEvent} from '@angular/cdk/testing/private';
77
import {
88
MAT_RADIO_DEFAULT_OPTIONS,
99
MatRadioButton,
@@ -15,8 +15,11 @@ import {
1515
describe('MDC-based MatRadio', () => {
1616
beforeEach(waitForAsync(() => {
1717
TestBed.configureTestingModule({
18-
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
19-
declarations: [
18+
imports: [
19+
MatRadioModule,
20+
FormsModule,
21+
ReactiveFormsModule,
22+
CommonModule,
2023
DisableableRadioButton,
2124
FocusableRadioButton,
2225
RadiosInsideRadioGroup,
@@ -965,8 +968,7 @@ describe('MatRadioDefaultOverrides', () => {
965968
describe('when MAT_RADIO_DEFAULT_OPTIONS overridden', () => {
966969
beforeEach(waitForAsync(() => {
967970
TestBed.configureTestingModule({
968-
imports: [MatRadioModule, FormsModule],
969-
declarations: [DefaultRadioButton, RadioButtonWithColorBinding],
971+
imports: [MatRadioModule, FormsModule, DefaultRadioButton, RadioButtonWithColorBinding],
970972
providers: [
971973
{
972974
provide: MAT_RADIO_DEFAULT_OPTIONS,
@@ -1021,6 +1023,8 @@ describe('MatRadioDefaultOverrides', () => {
10211023
</mat-radio-button>
10221024
</mat-radio-group>
10231025
`,
1026+
standalone: true,
1027+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
10241028
})
10251029
class RadiosInsideRadioGroup {
10261030
labelPos: 'before' | 'after';
@@ -1041,6 +1045,8 @@ class RadiosInsideRadioGroup {
10411045
<mat-radio-button value="leaf" checked>Bulbasaur</mat-radio-button>
10421046
</mat-radio-group>
10431047
`,
1048+
standalone: true,
1049+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
10441050
})
10451051
class RadiosInsidePreCheckedRadioGroup {}
10461052

@@ -1065,6 +1071,8 @@ class RadiosInsidePreCheckedRadioGroup {}
10651071
<mat-radio-button name="fruit" value="raspberry">Raspberry</mat-radio-button>
10661072
<mat-radio-button id="nameless" value="no-name">No name</mat-radio-button>
10671073
`,
1074+
standalone: true,
1075+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
10681076
})
10691077
class StandaloneRadioButtons {
10701078
ariaLabel: string = 'Banana';
@@ -1080,6 +1088,8 @@ class StandaloneRadioButtons {
10801088
}
10811089
</mat-radio-group>
10821090
`,
1091+
standalone: true,
1092+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
10831093
})
10841094
class RadioGroupWithNgModel {
10851095
modelValue: string;
@@ -1094,6 +1104,8 @@ class RadioGroupWithNgModel {
10941104

10951105
@Component({
10961106
template: `<mat-radio-button>One</mat-radio-button>`,
1107+
standalone: true,
1108+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
10971109
})
10981110
class DisableableRadioButton {
10991111
@ViewChild(MatRadioButton) matRadioButton: MatRadioButton;
@@ -1110,6 +1122,8 @@ class DisableableRadioButton {
11101122
<mat-radio-button value="2">Two</mat-radio-button>
11111123
</mat-radio-group>
11121124
`,
1125+
standalone: true,
1126+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11131127
})
11141128
class RadioGroupWithFormControl {
11151129
@ViewChild(MatRadioGroup) group: MatRadioGroup;
@@ -1118,6 +1132,8 @@ class RadioGroupWithFormControl {
11181132

11191133
@Component({
11201134
template: `<mat-radio-button [disabled]="disabled" [tabIndex]="tabIndex"></mat-radio-button>`,
1135+
standalone: true,
1136+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11211137
})
11221138
class FocusableRadioButton {
11231139
tabIndex: number;
@@ -1134,6 +1150,8 @@ class FocusableRadioButton {
11341150
}
11351151
</mat-radio-group>
11361152
`,
1153+
standalone: true,
1154+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11371155
})
11381156
class InterleavedRadioGroup {
11391157
modelValue = 'strawberry';
@@ -1149,21 +1167,29 @@ class InterleavedRadioGroup {
11491167
template: `
11501168
<div><ng-content></ng-content></div>
11511169
`,
1170+
standalone: true,
1171+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11521172
})
11531173
class TranscludingWrapper {}
11541174

11551175
@Component({
11561176
template: `<mat-radio-button tabindex="5"></mat-radio-button>`,
1177+
standalone: true,
1178+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11571179
})
11581180
class RadioButtonWithPredefinedTabindex {}
11591181

11601182
@Component({
11611183
template: `<mat-radio-button></mat-radio-button>`,
1184+
standalone: true,
1185+
imports: [MatRadioModule, FormsModule],
11621186
})
11631187
class DefaultRadioButton {}
11641188

11651189
@Component({
11661190
template: `<mat-radio-button color="warn"></mat-radio-button>`,
1191+
standalone: true,
1192+
imports: [MatRadioModule, FormsModule],
11671193
})
11681194
class RadioButtonWithColorBinding {}
11691195

@@ -1173,6 +1199,8 @@ class RadioButtonWithColorBinding {}
11731199
aria-label="Radio button"
11741200
aria-describedby="something"
11751201
aria-labelledby="something-else"></mat-radio-button>`,
1202+
standalone: true,
1203+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11761204
})
11771205
class RadioButtonWithPredefinedAriaAttributes {}
11781206

@@ -1192,6 +1220,8 @@ class RadioButtonWithPredefinedAriaAttributes {}
11921220
}
11931221
</mat-radio-group>
11941222
`,
1223+
standalone: true,
1224+
imports: [MatRadioModule, FormsModule, ReactiveFormsModule, CommonModule],
11951225
})
11961226
class PreselectedRadioWithStaticValueAndNgIf {
11971227
@ViewChild('preselectedGroup', {read: MatRadioGroup}) preselectedGroup: MatRadioGroup;

src/material/radio/radio.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
ViewChild,
3333
ViewEncapsulation,
3434
} from '@angular/core';
35-
import {ThemePalette} from '@angular/material/core';
35+
import {MatRipple, ThemePalette} from '@angular/material/core';
3636
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
3737
import {UniqueSelectionDispatcher} from '@angular/cdk/collections';
3838
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
@@ -102,6 +102,7 @@ export function MAT_RADIO_DEFAULT_OPTIONS_FACTORY(): MatRadioDefaultOptions {
102102
'role': 'radiogroup',
103103
'class': 'mat-mdc-radio-group',
104104
},
105+
standalone: true,
105106
})
106107
export class MatRadioGroup implements AfterContentInit, OnDestroy, ControlValueAccessor {
107108
/** Selected value for the radio group. */
@@ -368,6 +369,8 @@ export class MatRadioGroup implements AfterContentInit, OnDestroy, ControlValueA
368369
exportAs: 'matRadioButton',
369370
encapsulation: ViewEncapsulation.None,
370371
changeDetection: ChangeDetectionStrategy.OnPush,
372+
standalone: true,
373+
imports: [MatRipple],
371374
})
372375
export class MatRadioButton implements OnInit, AfterViewInit, DoCheck, OnDestroy {
373376
private _uniqueId: string = `mat-radio-${++nextUniqueId}`;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ describe('radio harness', () => {
1212

1313
beforeEach(async () => {
1414
await TestBed.configureTestingModule({
15-
imports: [MatRadioModule, ReactiveFormsModule],
16-
declarations: [MultipleRadioButtonsHarnessTest],
15+
imports: [MatRadioModule, ReactiveFormsModule, MultipleRadioButtonsHarnessTest],
1716
}).compileComponents();
1817

1918
fixture = TestBed.createComponent(MultipleRadioButtonsHarnessTest);
@@ -295,6 +294,8 @@ describe('radio harness', () => {
295294
<mat-radio-button [value]="false" [name]="thirdGroupButtonName"></mat-radio-button>
296295
</mat-radio-group>
297296
`,
297+
standalone: true,
298+
imports: [MatRadioModule, ReactiveFormsModule],
298299
})
299300
class MultipleRadioButtonsHarnessTest {
300301
values = ['opt1', 'opt2', 'opt3'];

tools/public_api_guard/material/radio.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { EventEmitter } from '@angular/core';
1414
import { FocusMonitor } from '@angular/cdk/a11y';
1515
import { FocusOrigin } from '@angular/cdk/a11y';
1616
import * as i0 from '@angular/core';
17-
import * as i2 from '@angular/material/core';
18-
import * as i3 from '@angular/common';
17+
import * as i1 from '@angular/material/core';
18+
import * as i2 from '@angular/common';
1919
import { InjectionToken } from '@angular/core';
2020
import { OnDestroy } from '@angular/core';
2121
import { OnInit } from '@angular/core';
@@ -92,7 +92,7 @@ export class MatRadioButton implements OnInit, AfterViewInit, DoCheck, OnDestroy
9292
get value(): any;
9393
set value(value: any);
9494
// (undocumented)
95-
static ɵcmp: i0.ɵɵComponentDeclaration<MatRadioButton, "mat-radio-button", ["matRadioButton"], { "id": { "alias": "id"; "required": false; }; "name": { "alias": "name"; "required": false; }; "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; }; "disableRipple": { "alias": "disableRipple"; "required": false; }; "tabIndex": { "alias": "tabIndex"; "required": false; }; "checked": { "alias": "checked"; "required": false; }; "value": { "alias": "value"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "required": { "alias": "required"; "required": false; }; "color": { "alias": "color"; "required": false; }; }, { "change": "change"; }, never, ["*"], false, never>;
95+
static ɵcmp: i0.ɵɵComponentDeclaration<MatRadioButton, "mat-radio-button", ["matRadioButton"], { "id": { "alias": "id"; "required": false; }; "name": { "alias": "name"; "required": false; }; "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; }; "disableRipple": { "alias": "disableRipple"; "required": false; }; "tabIndex": { "alias": "tabIndex"; "required": false; }; "checked": { "alias": "checked"; "required": false; }; "value": { "alias": "value"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "required": { "alias": "required"; "required": false; }; "color": { "alias": "color"; "required": false; }; }, { "change": "change"; }, never, ["*"], true, never>;
9696
// (undocumented)
9797
static ɵfac: i0.ɵɵFactoryDeclaration<MatRadioButton, [{ optional: true; }, null, null, null, null, { optional: true; }, { optional: true; }, { attribute: "tabindex"; }]>;
9898
}
@@ -150,7 +150,7 @@ export class MatRadioGroup implements AfterContentInit, OnDestroy, ControlValueA
150150
set value(newValue: any);
151151
writeValue(value: any): void;
152152
// (undocumented)
153-
static ɵdir: i0.ɵɵDirectiveDeclaration<MatRadioGroup, "mat-radio-group", ["matRadioGroup"], { "color": { "alias": "color"; "required": false; }; "name": { "alias": "name"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "value": { "alias": "value"; "required": false; }; "selected": { "alias": "selected"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "required": { "alias": "required"; "required": false; }; }, { "change": "change"; }, ["_radios"], never, false, never>;
153+
static ɵdir: i0.ɵɵDirectiveDeclaration<MatRadioGroup, "mat-radio-group", ["matRadioGroup"], { "color": { "alias": "color"; "required": false; }; "name": { "alias": "name"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "value": { "alias": "value"; "required": false; }; "selected": { "alias": "selected"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "required": { "alias": "required"; "required": false; }; }, { "change": "change"; }, ["_radios"], never, true, never>;
154154
// (undocumented)
155155
static ɵfac: i0.ɵɵFactoryDeclaration<MatRadioGroup, never>;
156156
}
@@ -162,7 +162,7 @@ export class MatRadioModule {
162162
// (undocumented)
163163
static ɵinj: i0.ɵɵInjectorDeclaration<MatRadioModule>;
164164
// (undocumented)
165-
static ɵmod: i0.ɵɵNgModuleDeclaration<MatRadioModule, [typeof i1.MatRadioGroup, typeof i1.MatRadioButton], [typeof i2.MatCommonModule, typeof i3.CommonModule, typeof i2.MatRippleModule], [typeof i2.MatCommonModule, typeof i1.MatRadioGroup, typeof i1.MatRadioButton]>;
165+
static ɵmod: i0.ɵɵNgModuleDeclaration<MatRadioModule, never, [typeof i1.MatCommonModule, typeof i2.CommonModule, typeof i1.MatRippleModule, typeof i3.MatRadioGroup, typeof i3.MatRadioButton], [typeof i1.MatCommonModule, typeof i3.MatRadioGroup, typeof i3.MatRadioButton]>;
166166
}
167167

168168
// (No @packageDocumentation comment for this package)

0 commit comments

Comments
 (0)