LaunchPadLab / lp-components

Our Components
http://lp-components.herokuapp.com
MIT License
5 stars 1 forks source link

Apply class name only to CheckboxGroup/RadioGroup container #467

Closed chawes13 closed 2 years ago

chawes13 commented 3 years ago

Currently, passing in the className prop to a field that uses the CheckboxGroup component will override the className prop on the outer fieldset, as well as the fieldset for each individual checkbox. This isn't ideal, since our base styling relies on CheckboxGroup and checkbox classes to exist on these fieldsets and it makes it harder to target the outer element. Since we can target the checkbox fieldsets via nesting, I'd propose that only the outer fieldset have the class name applied.

Proposed

<Field
  name="flavors"
  component={CheckboxGroup}
  className="CheckboxGroup flex"
/>

// Output
<fieldset class="CheckboxGroup flex">
  <fieldset class="checkbox" />
  <fieldset class="checkbox" />
  <fieldset class="checkbox" />
</fieldset>

// Styling
.CheckboxGroup {
  &.flex {
     display: flex;
     .checkbox {
       flex-shrink: 3;
     }
  }
}

Current


<Field
  name="flavors"
  component={CheckboxGroup}
  className="CheckboxGroup flex"
/>

// Output
<fieldset class="CheckboxGroup flex">
  <fieldset class="CheckboxGroup flex" />
  <fieldset class="CheckboxGroup flex" />
  <fieldset class="CheckboxGroup flex" />
</fieldset>
dpikt commented 3 years ago

Makes sense to me!

chawes13 commented 3 years ago

Relatedly, it would be nice to pass down props specifically to each checkbox. For example, a custom labelComponent. Thinking an api could look like checkboxProps. I'll try this out on CDK before porting it over