Add Spectrum CheckboxGroup component#1003
Conversation
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
| ...props, | ||
| isReadOnly: props.isReadOnly || state.isReadOnly, | ||
| isDisabled: props.isDisabled || state.isDisabled, | ||
| name: props.name || checkboxGroupNames.get(state) |
There was a problem hiding this comment.
This doesn't make sense for me unless I miss something. It seems important to keep the same name for all "checkbox group items" as this "groups" them when sending the containing form element.
There was a problem hiding this comment.
I was thinking it might be possible to have a single "group" client side, but maybe you submit to a server using separate names for each checkbox.
There was a problem hiding this comment.
from what i remember of form submission, there are some specials names that work with some servers? i think the name has to include "[]" on the end
if you don't include that then checkboxes with the same name will overwrite each other
but not everything recognizes that special name syntax, so probably better to have them be individually named and just 'look' like a group
There was a problem hiding this comment.
I was thinking it might be possible to have a single "group" client side, but maybe you submit to a server using separate names for each checkbox.
How realistic this use case is? Shouldn't this really be considered bad practice?
| interface CheckboxGroupAria { | ||
| /** Props for the checkbox group wrapper element. */ | ||
| checkboxGroupProps: HTMLAttributes<HTMLElement>, | ||
| groupProps: HTMLAttributes<HTMLElement>, |
There was a problem hiding this comment.
while I understand the sentiment to match against the returned role, isn't this confusing (DX-wise)? given that useRadioGroup returns radioGroupProps?
There was a problem hiding this comment.
Well, in that case the role is radiogroup.
There was a problem hiding this comment.
Right, the role is mainly opaque to users though - the point of React Aria is so people don't have to worry about this. Seems like one might not really know what exact role is being prefilled by React Aria in the returned objects, but they certainly know how the component that they have just used is named.
I don't care about this as much as TS will help me with this anyway but I kinda find the choice somewhat odd as the chosen name focuses on the low-level implementation detail that is hidden from the user, rather than on a high-level feature that is actually used directly by them.
| }, | ||
| addValue(value) { | ||
| if (props.isReadOnly) { | ||
| if (props.isReadOnly || props.isDisabled) { |
There was a problem hiding this comment.
this hasn't been covered by the related unit tests 😉
| name, | ||
| value: selectedValue, | ||
| value: selectedValues, | ||
| setValue, |
There was a problem hiding this comment.
if addValue, removeValue and toggleValue check props.isReadOnly || props.isDisabled before actually changing the value, shouldn't the same check apply here?
| expect(state.value).toEqual([]); | ||
| expect(state.isDisabled).toBe(false); | ||
| expect(state.isReadOnly).toBe(false); | ||
| expect(typeof state.setValue).toBe('function'); |
There was a problem hiding this comment.
this test should also check if isSelected is provided by the hook
| expect(state.isReadOnly).toBe(true); | ||
|
|
||
| return null; | ||
| } |
There was a problem hiding this comment.
would be great to add a simple test for isSelected functionality as well
There was a problem hiding this comment.
I guess. We tend not to do too much unit testing of the stately part by itself given that it's already covered by the ARIA/Spectrum tests indirectly. This tends to lead to more maintainable tests. But I suppose since the others are already tested I can add a quick one.
| @@ -160,7 +159,7 @@ describe('useCheckboxGroup', () => { | |||
| }); | |||
|
|
|||
| it('sets aria-disabled when isDisabled is true', () => { | |||
There was a problem hiding this comment.
I believe that those test names should be adjusted now as a little more than just aria-disabled is being tested here
|
Build successful! 🎉 |
Co-authored-by: Danni <drobinson@livefyre.com>
|
Build successful! 🎉 |
Followup from #868
Closes #798
This adds a
CheckboxGroupcomponent to@react-spectrum/checkbox. It follows the same styling as RadioGroup but for checkboxes. This component acceptsCheckboxelements as children, and passes the group state to them via context.Additional changes to the hooks:
namehandling was moved from stately to aria. This was a mistake in RadioGroup since it's web-specific and it's being deprecated and moved to aria in Fix remaining SSR tests #994. Also, for checkbox groups, there's no need to auto generate a form name like for radio groups, because the name isn't used by the browser for behavior. So we only need to pass through the given name for the group to each checkbox.isDisabledandisReadOnlyare now passed through from the group to the checkboxes automatically by storing the values in state.aria-invalidandrequiredDOM props are removed from individual checkboxes within a group since they don't make sense there. Instead, these are exposed at the group level, e.g. in Spectrum the necessity indicator can be used to specify that the group is required. This is up to individual design systems to implement.checkboxGroupPropsin the return value to justgroupPropsto match the pattern of using the aria role as the name of the property.Also renamed docs to a temp name so they don't get picked up by the deploy to prod before publishing.