Stack Exchange
I need to update the state of a radio button group with the label?
The below is from my Child Element (Step 2):
<input class="radioInput" type="radio" name="sex" value="male"
 onChange{(e) => props.setFormData({...props.formData, sex: e.target.value})}>
</input>
<label class="radioLabel" value="male" for="male"> Male </label>

<input class="radioInput" type="radio" name="sex" value="female"
 onChange{(e) => props.setFormData({...props.formData, sex: e.target.value})}>
</input>
<label class="radioLabel" value="female" for="female"> Female </label>

This is the Parent Element:
const [formData, setFormData] = useState({
 firstName: '',
 lastName: '',
 sex: 'male',
})

This is my CSS:
.radioInput[type="radio"] {
    display: inline-flex;
    overflow: hidden;
    opacity: 0;
    position: fixed;
}

.radioInput[type="radio"]:checked + label {
    background-color: rgb(253 224 71);
    border: 1px solid transparent;
}

.radioLabel {
    color:rgb(17 24 39);
    border: 1px solid rgb(209 213 219);
    border-radius: 0.375rem;
    text-align: center;
    padding: 8px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.1s;
}

.radioLabel:hover {
    border: 1px solid transparent;
    background-color: rgb(253 224 71);
}

Now when I allow the radio buttons to show the circle boxes to check, this works. However I want the styling to be as I've shown, but I'm struggling getting the buttons to change the state ...

React uses className not class in JSX: className="radioInput" for example.

The for attribute should match the id of the input. Documentation

Thank you both, the for attribute did fix the issue! I have also replaced the class for className too!
