Skip to content
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

Revamp Radio Component with A11Y #142

Merged
merged 8 commits into from
Nov 24, 2022
Merged

Conversation

djalmaaraujo
Copy link
Contributor

@djalmaaraujo djalmaaraujo commented Nov 23, 2022

Description

image

We are revamping the Radio component. Radio components only make sense to be used with two or more. That's the nature of Radios; you need two or more options.

The current implementation lets you choose only one Radio button. In this new implementation, you must pass an array of options (similar to other components). This will provide more clarity and avoid forms with one radio button, and this new implementation is accessible.

BREAKING CHANGE: The new implementation of the <Radio> will break current usage. Once you upgrade this component, you need to change the implementation. Follow the Storybook story to understand the new API.

Checklist

  • This PR has good automated test coverage
  • The storybook for the component has been updated

Steps to Test

  1. Pull down PR.
  2. npm run dev.
  3. Open http://localhost:6006/?path=/story/form-radio--default
  4. Test the functionality. Make sure you can click/select using the mouse or keyboard the toggle and the label

@djalmaaraujo djalmaaraujo requested review from luiztiago and a team November 23, 2022 22:10
@netlify
Copy link

netlify bot commented Nov 23, 2022

Deploy Preview for vip-design-system-components ready!

Name Link
🔨 Latest commit 74dc038
🔍 Latest deploy log https://app.netlify.com/sites/vip-design-system-components/deploys/637f7e1beb445d00081c39c9
😎 Deploy Preview https://deploy-preview-142--vip-design-system-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@djalmaaraujo djalmaaraujo force-pushed the fix/radio-button-click branch 2 times, most recently from 541eee6 to c900483 Compare November 24, 2022 08:11
@simonwheatley
Copy link

Thanks for the classes on each item, @djalmaaraujo

Copy link
Contributor

@brunobasto brunobasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing, @djalmaaraujo! Left a minor comment.

{ disabled, defaultValue, onChange, name = '', options = [], className, ...props },
forwardRef
) => {
const renderedOptions = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djalmaaraujo I wonder if the overhead of useMemo is beneficial here. I would guess the options array will likely be small (< 5), and I don't see any heavy processing happening inside the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brunobasto Might not be that much, indeed. The main reason I added it is because, usually, people do onChange with an inline-function. The parent will make this component re-render often, mainly because it's a form with many interactions.

as="label"
sx={ { display: 'block', mb: 2, color: 'muted' } }
const Label = React.forwardRef( ( { sx, ...rest }, forwardRef ) => (
<label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent!

@djalmaaraujo djalmaaraujo merged commit 7462fab into trunk Nov 24, 2022
@djalmaaraujo djalmaaraujo deleted the fix/radio-button-click branch November 24, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants