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

Add an escape hatch for a11y errors #1083

Merged
merged 3 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-moons-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Added an escape hatch to silence accessibility errors in development when the `UNSAFE_DISABLE_ACCESSIBILITY_ERRORS` environment variable is set to `true`.
19 changes: 15 additions & 4 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const webpack = require('webpack');

module.exports = {
stories: [
'../packages/**/*.stories.@(js|ts|tsx|mdx)',
Expand All @@ -20,12 +22,12 @@ module.exports = {
features: {
postcss: false,
},
webpackFinal: transpileModules,
managerWebpack: transpileModules,
webpackFinal: createWebpackConfig,
managerWebpack: createWebpackConfig,
};

// Transpile all node_modules under the @sumup/* namespace.
function transpileModules(config) {
function createWebpackConfig(config) {
// Transpile all node_modules under the @sumup/* namespace.
config.module.rules = config.module.rules.map((rule) => {
// Modify all rules that apply to story files.
if (
Expand All @@ -40,5 +42,14 @@ function transpileModules(config) {
}
return rule;
});
// Expose environment variables to Storybook
config.plugins = [
...config.plugins,
Copy link
Contributor Author

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

new webpack.DefinePlugin({
'process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS': JSON.stringify(
Copy link
Contributor Author

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

process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS,
),
}),
];
return config;
}
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Hamburger/Hamburger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const Hamburger = ({
...props
}: HamburgerProps): JSX.Element => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
(!activeLabel || !inactiveLabel)
Comment on lines +169 to 172
Copy link
Contributor Author

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

Copy link
Member

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 😕

Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const IconButton = forwardRef(
const child = Children.only(children);
const icon = cloneElement(child, { role: 'presentation' });
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/ImageInput/ImageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const ImageInput = ({
...props
}: ImageInputProps): JSX.Element => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
(!label || !clearButtonLabel || !loadingLabel)
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export const Input = forwardRef(
ref: InputProps['ref'],
): ReturnType => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const LoadingButton: FC<LoadingButtonProps> = ({
...props
}) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!loadingLabel
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const Modal: ModalComponent<ModalProps> = ({
...props
}) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!preventClose &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (typeof window !== 'undefined') {
if (appElement) {
ReactModal.setAppElement(appElement);
} else if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test'
) {
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const Pagination = ({
...props
}: PaginationProps): ReactNode => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
(!label || !previousLabel || !nextLabel)
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export function ProgressBar({
...props
}: ProgressBarProps): JSX.Element {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const RadioButtonGroup = forwardRef(
ref: RadioButtonGroupProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const SearchInput = forwardRef(
ref: SearchInputProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
onClear &&
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export const Select = forwardRef(
ref?: SelectProps['ref'],
): ReturnType => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const SelectorGroup = forwardRef(
ref: SelectorGroupProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const Aggregator = ({
...props
}: AggregatorProps): JSX.Element => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const TableHeader: FC<TableHeaderProps> = ({
...props
}) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
sortParams.sortable &&
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const Tag = forwardRef(
ref: BaseProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
onRemove &&
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const Toggle = forwardRef(
ref: ToggleProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const Switch = forwardRef(
ref: SwitchProps['ref'],
) => {
if (
process.env.UNSAFE_DISABLE_ACCESSIBILITY_ERRORS !== 'true' &&
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
(!checkedLabel || !uncheckedLabel)
Expand Down