If a lightning-radio-group
has two options, and a user selects one, I want to programmatically have the UI changed back to the other one.
Link to a playground with a simple example. (code copied below)
import { LightningElement, track } from 'lwc';
export default class RadioGroupRequired extends LightningElement {
@track value = 'option1';
get options() {
return [
{ label: 'Option one', value: 'option1' },
{ label: 'Option two', value: 'option2' },
];
}
handleOnChange(evt) {
this.value = 'option1';
// how to make the UI select Option one?
}
}
And the html:
<template>
<lightning-radio-group name="radioGroup"
label="Radio Group"
options={options}
value={value}
required
type="button"
onchange={handleOnChange}></lightning-radio-group>
value={value}
</template>
I think that there is no rerendering because the bind variable, {value}
doesn't actually change. However, the selected state of the lightning-radio-group does, and I want to be able to change it back. How can that be achieved?
I did not notice any methods or attributes that would seem to do the trick in the lightning-radio-group specification.