Skip to content

Form.Check: inconsistent checkbox label click handling #4056

@gagarski

Description

@gagarski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions