-
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 an escape hatch for a11y errors #1083
Conversation
This commit adds the condition to all files where the error would be thrown and configures the Storybook to also receive the environment variable from the CLI
🦋 Changeset detectedLatest commit: 82cb833 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/sumup/oss-circuit-ui/4zCdsTG66dYByCS1M4qd4cDUddBo |
Hey @robinmetral, Thanks! |
Codecov Report
@@ Coverage Diff @@
## next #1083 +/- ##
==========================================
+ Coverage 91.54% 91.59% +0.05%
==========================================
Files 165 165
Lines 2908 2926 +18
Branches 855 873 +18
==========================================
+ Hits 2662 2680 +18
Misses 233 233
Partials 13 13
|
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' && | ||
process.env.NODE_ENV !== 'production' && | ||
process.env.NODE_ENV !== 'test' && | ||
(!activeLabel || !inactiveLabel) |
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.
Wondering if there's a way to abstract this away somewhere to avoid 3 duplicate lines in 30ish components
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.
I don't think there is a way without adding a function call in production everywhere 😕
@@ -40,5 +42,14 @@ function transpileModules(config) { | |||
} | |||
return rule; | |||
}); | |||
// Expose environment variables to Storybook | |||
config.plugins = [ | |||
...config.plugins, |
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.
I'm not sure if this is necessary. I thought it couldn't hurt
config.plugins = [ | ||
...config.plugins, | ||
new webpack.DefinePlugin({ | ||
'process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS': JSON.stringify( |
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.
Note: here I had to use JSON.stringify()
as mentioned in the plugin's docs, but in the dashboard's Next.js config I didn't need to (doing so resulted in UNSAFE_DISABLE_ACCESSIBILITY_ERRORS === '"true"'
), I assume Next.js is doing it under the hood
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.
This is great! 🙌🏻
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' && | ||
process.env.NODE_ENV !== 'production' && | ||
process.env.NODE_ENV !== 'test' && | ||
(!activeLabel || !inactiveLabel) |
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.
I don't think there is a way without adding a function call in production everywhere 😕
Purpose
#1080 introduced a mechanism that throws at missing accessible labels across all components.
However, this would require large-scale change in some applications, so we're also providing an escape hatch to allow developers to work on their applications while labels are still not provided, for example while they're being written and localized.
The errors will not be thrown if the
UNSAFE_DISABLE_ACCESSIBILITY_ERRORS
environment variable is set totrue
.Note that depending on the application, this environment variable will need to be exposed differently.
In a Next.js application, it can be added in the
next.config.js
:In other applications, the Webpack config can be extended with the Webpack DefinePlugin:
(note: this is the approach this PR is taking for the Circuit UI Storybook)
Then, the variable can be set in the console to bypass accessibility errors in development:
Approach and changes
UNSAFE_DISABLE_ACCESSIBILITY_ERRORS
environment variable before throwing when labels are missing in developmentDefinition of done
[ ] Unit and integration tests[ ] Meets minimum browser support[ ] Meets accessibility requirements