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

7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.