Skip to content

Commit

Permalink
Fix axe failure
Browse files Browse the repository at this point in the history
- role="presentation" wasn't the correct way to fix the jsx/a11y lint complaint and has actual screen reader ramifications we don't want

- After discussing with trevor, the jsx/a11y lint is over-zealous in this case, the end-behavior works better for users with tabIndex and onKeydown, and the rule can be disabled
  • Loading branch information
cee-chen committed Nov 16, 2021
1 parent efb6b25 commit b2390e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/components/code/__snapshots__/code_block.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ exports[`EuiCodeBlock full screen displays content in fullscreen mode 1`] = `
<pre
className="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap"
onKeyDown={[Function]}
role="presentation"
tabIndex={0}
>
<code
Expand Down Expand Up @@ -762,7 +761,6 @@ exports[`EuiCodeBlock virtualization renders a virtualized code block 1`] = `
>
<pre
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap euiCodeBlock__pre--isVirtualized"
role="presentation"
style="position:relative;height:600px;width:600px;overflow:auto;-webkit-overflow-scrolling:touch;will-change:transform;direction:ltr"
tabindex="0"
>
Expand Down
12 changes: 5 additions & 7 deletions src/components/code/code_block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import {
highlightByLine,
} from './utils';

/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
// We're disabling the above a11y lint rule because it's valid for a tabIndex={0} element to have an onKeyDown event listener
// The onKeyDown is an enhancement for keyboard users, and the tabIndex enables overflow scrolling for keyboard users and enhances focus for screen reader users

// eslint-disable-next-line local/forward-ref
const virtualizedOuterElement = ({
className,
Expand All @@ -52,7 +56,6 @@ const virtualizedOuterElement = ({
ref={ref}
className={className}
tabIndex={0}
role="presentation"
onKeyDown={onKeyDown}
/>
))
Expand Down Expand Up @@ -386,12 +389,7 @@ export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({
)}
</EuiAutoSizer>
) : (
<pre
className={preClasses}
tabIndex={0}
role="presentation"
onKeyDown={onKeyDown}
>
<pre className={preClasses} tabIndex={0} onKeyDown={onKeyDown}>
<code {...codeProps}>{content}</code>
</pre>
)}
Expand Down

0 comments on commit b2390e9

Please sign in to comment.