Skip to content

Commit 098ed05

Browse files
thetaPCliamdebeasi
andauthored
chore(angular): remove radio value accessor (#28386)
Co-authored-by: Liam DeBeasi <[email protected]>
1 parent 7ba939f commit 098ed05

File tree

11 files changed

+64
-74
lines changed

11 files changed

+64
-74
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './boolean-value-accessor';
22
export * from './numeric-value-accessor';
3-
export * from './radio-value-accessor';
43
export * from './select-value-accessor';
54
export * from './text-value-accessor';

packages/angular/src/directives/control-value-accessors/radio-value-accessor.ts

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

packages/angular/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// DIRECTIVES
22
export { BooleanValueAccessorDirective as BooleanValueAccessor } from './directives/control-value-accessors/boolean-value-accessor';
33
export { NumericValueAccessorDirective as NumericValueAccessor } from './directives/control-value-accessors/numeric-value-accessor';
4-
export { RadioValueAccessorDirective as RadioValueAccessor } from './directives/control-value-accessors/radio-value-accessor';
54
export { SelectValueAccessorDirective as SelectValueAccessor } from './directives/control-value-accessors/select-value-accessor';
65
export { TextValueAccessorDirective as TextValueAccessor } from './directives/control-value-accessors/text-value-accessor';
76
export { IonTabs } from './directives/navigation/ion-tabs';

packages/angular/src/ionic-module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { appInitialize } from './app-initialize';
1313
import {
1414
BooleanValueAccessorDirective,
1515
NumericValueAccessorDirective,
16-
RadioValueAccessorDirective,
1716
SelectValueAccessorDirective,
1817
TextValueAccessorDirective,
1918
} from './directives/control-value-accessors';
@@ -41,7 +40,6 @@ const DECLARATIONS = [
4140
// ngModel accessors
4241
BooleanValueAccessorDirective,
4342
NumericValueAccessorDirective,
44-
RadioValueAccessorDirective,
4543
SelectValueAccessorDirective,
4644
TextValueAccessorDirective,
4745

packages/angular/standalone/src/directives/radio.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
ChangeDetectorRef,
4-
Component,
5-
ElementRef,
6-
EventEmitter,
7-
HostListener,
8-
Injector,
9-
NgZone,
10-
} from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
112
import type { OnInit } from '@angular/core';
12-
import { NG_VALUE_ACCESSOR } from '@angular/forms';
13-
import { ValueAccessor } from '@ionic/angular/common';
143
import type { Components } from '@ionic/core/components';
154
import { defineCustomElement } from '@ionic/core/components/ion-radio.js';
165

@@ -22,9 +11,9 @@ import { defineCustomElement } from '@ionic/core/components/ion-radio.js';
2211
* class) causes ng-packagr to output multiple component variables
2312
* which breaks treeshaking.
2413
* For example, the following would be generated:
25-
* let IonRadio = IonRadio_1 = class IonRadio extends ValueAccessor {
14+
* let IonRadio = IonRadio_1 = class IonRadio {
2615
* Instead, we want only want the class generated:
27-
* class IonRadio extends ValueAccessor {
16+
* class IonRadio {
2817
*/
2918
import { proxyInputs, proxyOutputs } from './angular-component-lib/utils';
3019

@@ -36,19 +25,11 @@ const RADIO_INPUTS = ['color', 'disabled', 'justify', 'labelPlacement', 'legacy'
3625
template: '<ng-content></ng-content>',
3726
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
3827
inputs: RADIO_INPUTS,
39-
providers: [
40-
{
41-
provide: NG_VALUE_ACCESSOR,
42-
useExisting: IonRadio,
43-
multi: true,
44-
},
45-
],
4628
standalone: true,
4729
})
48-
export class IonRadio extends ValueAccessor implements OnInit {
30+
export class IonRadio implements OnInit {
4931
protected el: HTMLElement;
50-
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone, injector: Injector) {
51-
super(injector, r);
32+
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
5233
defineCustomElement();
5334
c.detach();
5435
this.el = r.nativeElement;
@@ -63,15 +44,6 @@ export class IonRadio extends ValueAccessor implements OnInit {
6344
*/
6445
proxyInputs(IonRadio, RADIO_INPUTS);
6546
}
66-
67-
@HostListener('ionSelect', ['$event.target'])
68-
handleIonSelect(el: any): void {
69-
/**
70-
* The `el` type is any to access the `checked` state property
71-
* that is not exposed on the type interface.
72-
*/
73-
this.handleValueChange(el, el.checked);
74-
}
7547
}
7648

7749
export declare interface IonRadio extends Components.IonRadio {

packages/angular/test/base/e2e/src/lazy/form.spec.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('Form', () => {
3232
input2: 'Default Value',
3333
inputMin: 1,
3434
inputMax: 1,
35-
checkbox: false
35+
checkbox: false,
36+
radio: null
3637
});
3738
});
3839

@@ -59,7 +60,8 @@ describe('Form', () => {
5960
input2: 'Default Value',
6061
inputMin: 1,
6162
inputMax: 1,
62-
checkbox: false
63+
checkbox: false,
64+
radio: null
6365
});
6466
});
6567

@@ -73,7 +75,8 @@ describe('Form', () => {
7375
input2: 'Default Value',
7476
inputMin: 1,
7577
inputMax: 1,
76-
checkbox: false
78+
checkbox: false,
79+
radio: null
7780
});
7881
});
7982

@@ -87,7 +90,23 @@ describe('Form', () => {
8790
input2: 'Default Value',
8891
inputMin: 1,
8992
inputMax: 1,
90-
checkbox: true
93+
checkbox: true,
94+
radio: null
95+
});
96+
});
97+
98+
it('ion-radio should change', () => {
99+
cy.get('ion-radio').click();
100+
testData({
101+
datetime: '2010-08-20',
102+
select: null,
103+
toggle: false,
104+
input: '',
105+
input2: 'Default Value',
106+
inputMin: 1,
107+
inputMax: 1,
108+
checkbox: false,
109+
radio: 'nes'
91110
});
92111
});
93112

@@ -109,7 +128,8 @@ describe('Form', () => {
109128
input2: 'Default Value',
110129
inputMin: 1,
111130
inputMax: 1,
112-
checkbox: false
131+
checkbox: false,
132+
radio: null
113133
});
114134
cy.get('ion-checkbox').click();
115135
testData({
@@ -120,7 +140,8 @@ describe('Form', () => {
120140
input2: 'Default Value',
121141
inputMin: 1,
122142
inputMax: 1,
123-
checkbox: true
143+
checkbox: true,
144+
radio: null
124145
});
125146
});
126147
});

packages/angular/test/base/e2e/src/lazy/inputs.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('Inputs', () => {
55

66
it('should have default value', () => {
77
cy.get('ion-checkbox').should('have.prop', 'checked').and('equal', true);
8+
cy.get('ion-radio-group').should('have.prop', 'value').and('equal', 'nes');
89
cy.get('ion-toggle').should('have.prop', 'checked').and('equal', true);
910
cy.get('ion-input').should('have.prop', 'value').and('equal', 'some text');
1011
cy.get('ion-datetime').should('have.prop', 'value').and('equal', '1994-03-15');
@@ -15,6 +16,7 @@ describe('Inputs', () => {
1516
cy.get('#reset-button').click();
1617

1718
cy.get('ion-checkbox').should('have.prop', 'checked').and('equal', false);
19+
cy.get('ion-radio-group').should('not.have.prop', 'value');
1820
cy.get('ion-toggle').should('have.prop', 'checked').and('equal', false);
1921
/**
2022
* The `value` property gets set to undefined
@@ -32,6 +34,7 @@ describe('Inputs', () => {
3234
cy.get('#set-button').click();
3335

3436
cy.get('ion-checkbox').should('have.prop', 'checked').and('equal', true);
37+
cy.get('ion-radio-group').should('have.prop', 'value').and('equal', 'nes');
3538
cy.get('ion-toggle').should('have.prop', 'checked').and('equal', true);
3639
cy.get('ion-input').should('have.prop', 'value').and('equal', 'some text');
3740
cy.get('ion-datetime').should('have.prop', 'value').and('equal', '1994-03-15');
@@ -42,6 +45,7 @@ describe('Inputs', () => {
4245
cy.get('#reset-button').click();
4346

4447
cy.get('ion-checkbox#first-checkbox').click();
48+
cy.get('ion-radio').first().click();
4549
cy.get('ion-toggle').first().click();
4650

4751
cy.get('ion-input').eq(0).type('hola');
@@ -58,6 +62,7 @@ describe('Inputs', () => {
5862
cy.get('ion-alert .alert-button:not(.alert-button-role-cancel)').click();
5963

6064
cy.get('#checkbox-note').should('have.text', 'true');
65+
cy.get('#radio-note').should('have.text', 'nes');
6166
cy.get('#toggle-note').should('have.text', 'true');
6267
cy.get('#input-note').should('have.text', 'hola');
6368
cy.get('#datetime-note').should('have.text', '1994-03-14');

packages/angular/test/base/src/app/lazy/form/form.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
<ion-checkbox formControlName="checkbox"> Checkbox </ion-checkbox>
4949
</ion-item>
5050

51+
<ion-item>
52+
<ion-radio-group formControlName="radio">
53+
<ion-radio value="nes">Radio</ion-radio>
54+
</ion-radio-group>
55+
</ion-item>
56+
5157
<ion-item>
5258
<ion-label>Min</ion-label>
5359
<ion-input formControlName="inputMin" type="number"></ion-input>

packages/angular/test/base/src/app/lazy/form/form.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class FormComponent {
2020
input2: ['Default Value'],
2121
inputMin: [1, Validators.min(1)],
2222
inputMax: [1, Validators.max(1)],
23-
checkbox: [false]
23+
checkbox: [false],
24+
radio: [undefined]
2425
}, {
2526
updateOn: typeof (window as any) !== 'undefined' && window.location.hash === '#blur' ? 'blur' : 'change'
2627
});
@@ -44,7 +45,8 @@ export class FormComponent {
4445
toggle: true,
4546
input: 'Some value',
4647
input2: 'Another values',
47-
checkbox: true
48+
checkbox: true,
49+
radio: 'nes'
4850
});
4951
}
5052

packages/angular/test/base/src/app/lazy/inputs/inputs.component.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@
8585
<ion-note slot="end">{{checkbox}}</ion-note>
8686
</ion-item>
8787

88+
<ion-item>
89+
<ion-radio-group value="nes" [(ngModel)]="radio" id="first-radio">
90+
<ion-radio value="nes">Radio</ion-radio>
91+
</ion-radio-group>
92+
<ion-note slot="end" id="radio-note">{{radio}}</ion-note>
93+
</ion-item>
94+
95+
<ion-item color="dark">
96+
<ion-radio-group value="nes" [(ngModel)]="radio">
97+
<ion-radio value="nes">Radio Mirror</ion-radio>
98+
</ion-radio-group>
99+
<ion-note slot="end">{{radio}}</ion-note>
100+
</ion-item>
101+
88102
</ion-list>
89103
<p>
90104
<ion-button (click)="setValues()" id="set-button">Set values</ion-button>

0 commit comments

Comments
 (0)