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

chore(fuselage): Modal a11y improvements #1149

Merged
merged 1 commit into from
Aug 29, 2023
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
29 changes: 25 additions & 4 deletions packages/fuselage/src/components/Modal/Modal.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import Modal from '.';
import * as stories from './Modal.stories';

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
]);

describe('[Modal Component]', () => {
it('renders without crashing', () => {
render(<Modal />);
});
test.each(testCases)(
`renders %s without crashing`,
async (_storyname, Story) => {
const tree = render(<Story />);
expect(tree.baseElement).toMatchSnapshot();
}
);

test.each(testCases)(
'%s should have no a11y violations',
async (_storyname, Story) => {
const { container } = render(<Story />);

const results = await axe(container);
expect(results).toHaveNoViolations();
}
);
});
17 changes: 9 additions & 8 deletions packages/fuselage/src/components/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { action } from '@storybook/addon-actions';
import type { ComponentStory } from '@storybook/react';
import type { ComponentProps } from 'react';
import React from 'react';

Expand All @@ -12,7 +13,7 @@ export default {
},
};

export const Default = () => (
export const Default: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.HeaderText>
Expand All @@ -32,7 +33,7 @@ export const Default = () => (
</Modal>
);

export const _WithThumb = () => (
export const _WithThumb: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.Thumb url='data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==' />
Expand All @@ -53,7 +54,7 @@ export const _WithThumb = () => (
</Modal>
);

export const _WithIcon = () => (
export const _WithIcon: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.Icon name='info' />
Expand All @@ -74,7 +75,7 @@ export const _WithIcon = () => (
</Modal>
);

export const _WithTagline = () => (
export const _WithTagline: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.HeaderText>
Expand All @@ -95,7 +96,7 @@ export const _WithTagline = () => (
</Modal>
);

export const _WithIconAndTagline = () => (
export const _WithIconAndTagline: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.Icon alignItems='end' name='info' />
Expand All @@ -117,7 +118,7 @@ export const _WithIconAndTagline = () => (
</Modal>
);

export const _WithAnnotation = () => (
export const _WithAnnotation: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.HeaderText>
Expand All @@ -138,7 +139,7 @@ export const _WithAnnotation = () => (
</Modal>
);

export const _WithHeroImage = () => (
export const _WithHeroImage: ComponentStory<typeof Modal> = () => (
<Modal>
<Modal.Header>
<Modal.HeaderText>
Expand Down Expand Up @@ -181,7 +182,7 @@ const FormContainer = (props: ComponentProps<typeof Box>) => (
/>
);

export const WithForm = () => (
export const _WithForm: ComponentStory<typeof Modal> = () => (
<Modal wrapper={FormContainer}>
<Modal.Header>
<Modal.HeaderText>
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Modal = forwardRef(
} as const;

return (
<Box is='dialog' rcx-modal ref={ref} {...props}>
<Box is='dialog' aria-modal='true' rcx-modal ref={ref} {...props}>
{wrapperFunction
? wrapperFunction(wrapperProps)
: createElement(wrapper, wrapperProps)}
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/src/components/Modal/ModalTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Box from '../Box';
export type ModalTitleProps = ComponentProps<typeof Box>;

export const ModalTitle = ({ children, ...props }: ModalTitleProps) => (
<Box rcx-modal__title {...props}>
<Box is='h2' rcx-modal__title {...props}>
{children}
</Box>
);
Loading
Loading