How to select lightning radio input in such a way that it deselects the other radiobuttons automatically

htmljavascriptlightning-web-components

Need help with fixing radiobuttion selection. In the image, you can see all buttons selected but only one button should be selected and others should be deselected automatically. with Standard HTML Input type radio, it works fine. But I want to try with Lightning Input radio button

Component Page
enter image description here

HTML CODE
enter image description here

Best Answer

You need to specify a name and value, just as you would in normal HTML.

<lightning-input name={item.id} type="radio" value={item.options.a}></lightning-input>

This will allow you to get the radio behavior, as well as tell which item is selected.

Note that the name must be the same for all type="radio" that should behave as a single radio selection, which is why I used item.id as the unique name. You can derive another name if you desire, just make sure they are unique on the page.

Demo.