-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Let's start with a simple case: an uncontrolled radio button:
<Form.Check label="Employee"
type="radio"
id="employee-radio"
/>
It checks when you either click the button itself or when you click the "Employee" label. This is quite the same as shown on demo page.
Checkboxes and radio buttons work the same way with a vanilla bootstrap: https://getbootstrap.com/docs/4.3/components/forms/
Now let's make this radio button controlled:
<Form.Check label="Employee"
type="radio"
id="employee-radio"
checked={this.props.mode == "employee"}
onChange={() => this.onChange("employee")}
/>
Now it works a bit different: you should click the button itself, clicks on "Employee" label are ignored.
Now if you want to handle label clicks you should fully customize the Form.Check rendering as shown here.
Considering that clickable checkbox and radio buttons label are quite native in bootstrap you probably would want to do it for every controlled checkbox and radio button you have.
My suggestion is to always call onChange when clicking to label which is defined as a string property (the simple Form.Check case without customization).
An alternative would be to add a way to customize this behavior with Form.Check properties (a boolean flag or a custom onLabelClick handler) but I don't like it very much. I think the best way would be to implement the most common case by default (which I believe clickable labels are) and let the user customize this behavior by passing Form.Check children.