palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.73k stars 2.18k forks source link

Radio buttons inside divs are not firing onChange events. #6619

Open MustaphaGheribi opened 10 months ago

MustaphaGheribi commented 10 months ago

Environment

Question

I'm trying to setup a list of radio buttons but the onChange event doesn't seem to be firing when the radio buttons are inside divs.

Code sandbox

Steps to reproduce:

adidahiya commented 10 months ago

@MustaphaGheribi this is because RadioGroup inspects and injects props into its children which are Radio or RadioCard components:

https://github.com/palantir/blueprint/blob/d8a5e6ae95884ae9866bf717a926411543341597/packages/core/src/components/forms/radioGroup.tsx#L103-L117

I'm curious why do you need to wrap your Radio components in a div?

MustaphaGheribi commented 10 months ago

@adidahiya here's an example usecase

<div className="dialogContent">
  <div className="wrapper">
    <RadioGroup
      onChange={handleRadioGroupChange}
      selectedValue="optionOne"
    >
      <div className="radioContainerOne">
        <Radio
          label="Option 1"
          value="optionOne"
          name="groupOne"
          className="customRadioStyle"

        />
      </div>
      <div className="radioContainerTwo">
        <div className="rowStyle">
          <Radio
            label="Option 2"
            value="optionTwo"
            name="groupOne"
            className="customRadioStyle"
          />
        </div>
      </div>
    </RadioGroup>
  </div>
</div>
adidahiya commented 10 months ago

@MustaphaGheribi I see your HTML, but what are you functionally trying to achieve with the extra div elements here?

MustaphaGheribi commented 10 months ago

@adidahiya the divs are there for css styling.

adidahiya commented 10 months ago

@MustaphaGheribi what kind of styling specifically? Can you demo this in your code sandbox? Can you achieve the same styling by targeting the .bp5-radio element in your styling code?