2

Once selected, radio buttons cannot be deselected. Is there a way to reset the lightning-radio-group component or deselect the selected option?

1 Answer 1

8

Just set the value to undefined like so:

<template>
    <lightning-radio-group name="radioGroup"
                        label="Radio Group"
                        options={options}
                        value={value}
                        onchange={handleRadioChange}
                        type="radio"></lightning-radio-group>
    <lightning-button label="Reset" onclick={handleResetClick}></lightning-button>
</template>
import { LightningElement } from 'lwc';

export default class App extends LightningElement {
    options = [
        {label: 'a', value: 'a'},
        {label: 'b', value: 'b'},
        {label: 'c', value: 'c'},
    ];
    value;

    handleRadioChange(event) {
        console.log(event.target.value);
        this.value = event.target.value;
    }

    handleResetClick() {
        this.value = undefined;
    }
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .