Skip to content

Commit

Permalink
Merge pull request #73 from Automattic/fix/code-a11y-issues
Browse files Browse the repository at this point in the history
Improve <Code> a11y
  • Loading branch information
djalmaaraujo committed Jul 4, 2022
2 parents 5a4a185 + 01ae060 commit 2ab5620
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/system/Code/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Code = ( { prompt = false, showCopy = false, onCopy = null, className, ...
{ codeDom }
{
<button
aria-label="Copy"
aria-label="Copy code"
sx={ {
bg: 'grey.10',
borderTopRightRadius: 1,
Expand Down Expand Up @@ -79,7 +79,11 @@ const Code = ( { prompt = false, showCopy = false, onCopy = null, className, ...
}
} }
>
{ copied ? 'Copied!' : <MdContentCopy /> }
{ copied ? (
<span role="alert">Code copied to clipboard</span>
) : (
<MdContentCopy aria-hidden="true" />
) }
</button>
}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/system/Code/Code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe( '<Code />', () => {
const props = { ...defaultProps, showCopy: true };
const { container } = render( <Code { ...props }>This is a code</Code> );

expect( screen.getByRole( 'button', { name: 'Copy' } ) ).toBeInTheDocument();
expect( screen.getByRole( 'button', { name: 'Copy code' } ) ).toBeInTheDocument();

// Check for accessibility issues
await expect( await axe( container ) ).toHaveNoViolations();
Expand All @@ -44,11 +44,11 @@ describe( '<Code />', () => {
const props = { ...defaultProps, showCopy: true };
const { container } = render( <Code { ...props }>This is a code</Code> );

fireEvent.click( screen.getByRole( 'button', { name: 'Copy' } ) );
fireEvent.click( screen.getByRole( 'button', { name: 'Copy code' } ) );

await waitFor( () => new Promise( res => setTimeout( res, 0 ) ) );

expect( screen.getByText( 'Copied!' ) ).toBeInTheDocument();
expect( screen.getByText( 'Code copied to clipboard' ) ).toBeInTheDocument();

// Check for accessibility issues
await expect( await axe( container ) ).toHaveNoViolations();
Expand Down

0 comments on commit 2ab5620

Please sign in to comment.