-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create RadioGroup component #1683
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1683 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 66 +2
Lines 1084 1114 +30
Branches 420 434 +14
=========================================
+ Hits 1084 1114 +30 ☔ View full report in Codecov by Sentry. |
2f62da0
to
84ab1e6
Compare
41d893b
to
694a9f5
Compare
1874a2b
to
332a977
Compare
The prop is called |
Not as far as I know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks very good. Some notes:
- The US spelling of "Labeled" as a single "l". We should use that everywhere.
aria-labelledby
is a mistake (see links in my comments) - Setting inputs via an array will work for the moment, but it means we can't add custom content to items, so we may have to revise the API if that use case comes up
- The intro of the documentation needs a revision. I suggest we link to the APG pattern for cases where our components are implementations of those patterns. These guides describe the purpose, expected keyboard behavior and semantic labeling. If we choose to deviate from aspects of a pattern, we should note why.
src/pattern-library/components/patterns/input/RadioGroupPage.tsx
Outdated
Show resolved
Hide resolved
</p> | ||
<p> | ||
Radios can be focused via arrow keys. Right/Left for horizontal{' '} | ||
<code>RadioGroup</code>s, and Up/Down for vertical ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keyboard navigation works as expected when the radio group is focused using tab, but I found that in Safari if I focused an item using the mouse and then navigated using the keyboard, the focus ring was not always rendered. In Chrome the focus ring is rendered as expected. I think this issue could be deferred to a subsequent PR.
src/pattern-library/components/patterns/input/RadioGroupPage.tsx
Outdated
Show resolved
Hide resolved
Good point. I see some differences on how it is described there and the behavior I implemented. I will fix those. |
8b48357
to
a3e94cf
Compare
6c098b4
to
cbdc35e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
cbdc35e
to
306653f
Compare
Add a new
RadioGroup
component withrole="radiogroup"
that renders a group of items withrole="radio"
in it.This implementation is inspired by how popular component libraries like MUI and Healdess UI do it, but is more simplistic for now.
Todo
items
prop and providing radios via<RadioGroup.Radio />
components.Implementation decisions
To simplify the implementation for now, the list of radios is passed via theitems={[...]}
prop as an array of objects.We could alternatively take a more declarative approach as we did with
Select
, and instead expose a<RadioGroup.Radio />
component that gets the selected value and handlers via context, and lets the rest of the props be passed by the consumers:EDIT: This is what I finally did, as we found two benefits for this approach:
direction
prop.I initially had the intention to build this component on top of
RadioButton
(see Create RadioButtonGroup component #1682), but once I got hands-on, I realized it was impractical for a few reasons:RadioButton
allows. This forces the use of role="radio" so that it can be focused and interacted with the keyboard, but then we end up with a radio containing another radio, which I don't think is correct from an accessibility point of view.RadioButton
, via classes or similar, but it feels like a hack just for the sake of usingRadioButton
.RadioButton
provides its own disabling capability viadisabled
prop, which among other things adds a 70% opacity to the component. If we do something similar in the wrapper, we would end up adding-up the 70% opacity twice just in part of the component, making it look like part of it is "more disabled".