-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a CheckboxGroup component #1815
Comments
Hi, Would that be useful to make a PR with our implementation ? How do you imagine the surface API ? We have something close to : <Label id="monsterAttributesLabel">Choose your monster's features:</Label>
<CheckboxesGroup
data-testid={`monster-attributes-container`}
name={`monster-attributes`}
aria-labelledby={`monsterAttributesLabel`}
toggleAllLabel="toggle all attributes!"
onChange={(e) => setSelectedCheckboxes(e.details.value)}
required={true}
readOnly={false}
disabled={false}
minRequired={1}
options={[
{ label: 'Scales', value: 'scales', checked: true },
{ label: 'Horns', value: 'horns', checked: false },
{ label: 'Claws', value: 'claws', disabled: true },
]}
/> Many of the properties above are optional. I just put many things to show you quickly what we have.
You can also omit the |
Thanks for this @long-lazuli! As a first step I'd focus on a simple two-state checkbox group (which doesn't require design changes, just improves DX and accessibility). What you're describing is the tri-state checkbox pattern and I think we could consider it as a next step, depending on demand from teams. We'd start with a design phase for this as well |
It's in fact a group of two-state checkboxes, |
Thanks for clarifying 🙌 I'd still start with the two-state group (technical improvement, no design changes) and then look into more complex patterns as a second step 🙂 The one you're describing might be tricky in terms of a11y—at least I can't find examples of it and we'd need to do more research (pointers welcome) |
I know we need to investigate that ( see #1415 ). Recently, we actually copied this component from one project to another one; but it would be better if it was here in Circuit. |
I think that @tranhoangan22 wanted to contribute the |
Wouldn't that be simpler to just rename Then for options, we do something like : options.map(
({ label: optionLabel, value, className, style, ...rest }) => (
<div
key={value && value.toString()}
className={className}
style={style}
>
{createElement(multiple ? Checkbox : RadioButton, {
...{ ...rest, value, name, required, onChange },
checked: value === activeValue,
label: optionLabel,
})}
</div>
),
)} It would force us to take care of the homogeneity of the two types ( |
👀 TBH that's a pretty good idea. The components would probably be fairly similar. I'd probably still export a Still to be explored to make sure that we can extend the right HTMLAttributes but I like the idea 💡 we also already do something like this in the |
I've noticed there are some differences between the
I would think it may be still a better idea to keep the implementations of |
Sounds good to me. Just FYI:
In the
This should be aligned in a future major. All input components should accept a Let's start with separate implementations for now, they can always be merged moving forward when form components are more consistent |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Add a comment explaining why the issue is still relevant to prevent it from being closed. |
This is being worked on in #1851. |
Fantastic news! The CheckboxGroup was released as part of Circuit UI v6.9 🎉 Big thanks to @tranhoangan22 for the contribution! |
Visual
No visuals yet. Refer to the
RadioButtonGroup
for inspirationContext
Circuit UI has a
Checkbox
component but noCheckboxGroup
component.Such a component is used in situations when the checkboxes are all grouped under one label, for example (from MDN):
This example shouldn't just use two checkboxes—it requires extra markup to make sure checkboxes are programatically grouped:
A similar markup is used by the
RadioButtonGoup
component (replacing checkboxes by radio buttons). TheSelectorGroup
component (when passed themultiple
prop) has the same underlying markup, but a different UI.The text was updated successfully, but these errors were encountered: