mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 16:16:41 +08:00
fix(radio): fix radio not showing checked state when not in a group (#24423)
This commit is contained in:
@ -22,6 +22,7 @@ import { createColorClasses, hostContext } from '../../utils/theme';
|
|||||||
export class Radio implements ComponentInterface {
|
export class Radio implements ComponentInterface {
|
||||||
private inputId = `ion-rb-${radioButtonIds++}`;
|
private inputId = `ion-rb-${radioButtonIds++}`;
|
||||||
private radioGroup: HTMLIonRadioGroupElement | null = null;
|
private radioGroup: HTMLIonRadioGroupElement | null = null;
|
||||||
|
private nativeInput!: HTMLInputElement;
|
||||||
|
|
||||||
@Element() el!: HTMLIonRadioElement;
|
@Element() el!: HTMLIonRadioElement;
|
||||||
|
|
||||||
@ -128,6 +129,10 @@ export class Radio implements ComponentInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onClick = () => {
|
||||||
|
this.checked = this.nativeInput.checked;
|
||||||
|
};
|
||||||
|
|
||||||
private onFocus = () => {
|
private onFocus = () => {
|
||||||
this.ionFocus.emit();
|
this.ionFocus.emit();
|
||||||
}
|
}
|
||||||
@ -150,6 +155,7 @@ export class Radio implements ComponentInterface {
|
|||||||
tabindex={buttonTabindex}
|
tabindex={buttonTabindex}
|
||||||
onFocus={this.onFocus}
|
onFocus={this.onFocus}
|
||||||
onBlur={this.onBlur}
|
onBlur={this.onBlur}
|
||||||
|
onClick={this.onClick}
|
||||||
class={createColorClasses(color, {
|
class={createColorClasses(color, {
|
||||||
[mode]: true,
|
[mode]: true,
|
||||||
'in-item': hostContext('ion-item', el),
|
'in-item': hostContext('ion-item', el),
|
||||||
@ -171,6 +177,7 @@ export class Radio implements ComponentInterface {
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
id={inputId}
|
id={inputId}
|
||||||
|
ref={el => this.nativeInput = el as HTMLInputElement}
|
||||||
/>
|
/>
|
||||||
</Host>
|
</Host>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -7,6 +7,14 @@ test('radio: basic', async () => {
|
|||||||
|
|
||||||
const compare = await page.compareScreenshot();
|
const compare = await page.compareScreenshot();
|
||||||
expect(compare).toMatchScreenshot();
|
expect(compare).toMatchScreenshot();
|
||||||
|
|
||||||
|
const groupedRadio = await page.find('#groupedRadio');
|
||||||
|
await groupedRadio.click();
|
||||||
|
expect(groupedRadio).toHaveClass('radio-checked');
|
||||||
|
|
||||||
|
const ungroupedRadio = await page.find('#ungroupedRadio');
|
||||||
|
await ungroupedRadio.click();
|
||||||
|
expect(ungroupedRadio).toHaveClass('radio-checked');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('radio:rtl: basic', async () => {
|
test('radio:rtl: basic', async () => {
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label>Pepperoni</ion-label>
|
<ion-label>Pepperoni</ion-label>
|
||||||
<ion-radio slot="start" value="pepperoni"></ion-radio>
|
<ion-radio slot="start" value="pepperoni" id="groupedRadio"></ion-radio>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item>
|
<ion-item>
|
||||||
@ -137,7 +137,7 @@
|
|||||||
</ion-list-header>
|
</ion-list-header>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label>Kiwi, (ionChange) Secondary color</ion-label>
|
<ion-label>Kiwi, (ionChange) Secondary color</ion-label>
|
||||||
<ion-radio slot="start" color="secondary"></ion-radio>
|
<ion-radio slot="start" color="secondary" id="ungroupedRadio"></ion-radio>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item>
|
<ion-item>
|
||||||
|
|||||||
Reference in New Issue
Block a user