-
Notifications
You must be signed in to change notification settings - Fork 842
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
[EuiCodeBlock] Improve accessibility of expandable code blocks #8195
base: main
Are you sure you want to change the base?
[EuiCodeBlock] Improve accessibility of expandable code blocks #8195
Conversation
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.
The changes look clean and the result is as expected, yay! 🥳 The code block is announced correctly both on focus and expansion.
I tried EuiCodeBlock
with and without overflowHeight
and isCopyable
set.
2 questions:
- Do you think it would be sensible to cover this by an automated a11y test?
- Do we want this first approved by an accessibility contractor? Maybe it would be useful to make it a part of all (/most) accessibility tickets and have this check in the PR template?
Role and label:
VoiceOver:
no overflowHeight
set:
Screen.Recording.2024-11-29.at.15.10.26.mov
overflowHeight
set to 1:
Screen.Recording.2024-11-29.at.15.11.01.mov
overflowHeight
set to 1 and isCopyable
to true:
Screen.Recording.2024-11-29.at.15.13.13.mov
Note: IMO the UX for copying the content could be improved. There's no information that the content has been copied on clicking the button.
I have 2 more suggestions and a question below 👇🏻
return showFullScreenButton ? ( | ||
isFullScreen ? ( | ||
// use delay to prevent label being updated in non-fullscreen state before fullscreen is opened | ||
// otherwise this causes screen readers to read the collapse label before anything else (as the button was focused when opening) |
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.
non-blocking question: By "read (...) before anything else" we mean before the information that a dialog has opened?
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.
Yes, because how its build currently it uses the same button outside and inside the fullscreen dialog.
It seemed while the "Expand" button is focused and then opened and updated based on the isFullscreen
condition it's already read out before the dialog had properly opened and applied focus to read the intended content instead.
); | ||
// pre tags don't accept aria-label without an | ||
// appropriate role, we add a SR only text instead | ||
const codeBlockLabelElement = ( |
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.
praise: That's a clever workaround 👍🏻 it does generate some code because we need to strip the screen-reader-only content before copying but it's clean.
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.
Fyi, I'm reusing the screen-reader-only copy mechanics introduced in this PR
@L1nBra Could you have a look as well (ref original issue)? |
We could add a general test to cover keyboard navigation, yes. Beyond that we couldn't test much further as we can't assert screen reader output. (unless we implement something like guidepup)
Thanks for the reminder, I wanted to ping the contractor yesterday but forgot 😅 I'm not sure this needs to be a standard per se. 🤔 If we add it we should make it a) optional (default) and b) non-blocker. |
@weronikaolejniczak Thanks for checking in VoiceOver! That's great to have an additional check. Just fyi, we need to keep in mind that VoiceOver is not the screen reader used by the majority of screen reader users. (there is no statistics but the regular Webaim screen reader surveys give us some idea) |
Preview staging links for this PR:
|
💔 Build Failed
Failed CI StepsHistory
|
Summary
closes #8175.
This PR aims to improve the accessibility of the
EuiCodeBlock
component, especially the expandable/fullscreen functionality.Accessibility issues
height
is set to provide scrolling via arrow keys - similar to a listbox pattern)Changes
<pre>
elements don't have any semantic information (without adding a specificrole
) and hence also don't supportaria-label
to add additional semantic information directly.<code>
elements don't acceptaria-label
and similar attributes either.To address this a screen-reader only text was added inside the element to be read with the content. This includes the
language
prop of the code block to increase context.The fullscreen wrapper was not semantically marked and therefore did not provide any information about context change. The container is fullscreen and it has a focus trap, therefore it should be semantically defined as a dialog. Additionally this allows to apply an
aria-label
to the element, providing context on opening the dialog.This will result in the following experience:
ArrowUp/Down
keys navigate the code block content line by line (screen reader browse modes)Escape
key anywhere in the dialog closes the dialog and returns the focus to the expand buttonEnter
key on it closes the dialog and returns the focus to the expand buttonThis PR adds a small change to the toggle functionality to ensure the focus is returned to the expand button when closing the fullscreen dialog.
Testing
NVDA
Screen.Recording.2024-11-28.at.15.37.22.mov
JAWS
Screen.Recording.2024-11-28.at.15.35.41.mov
QA
overflowHeight
control to50
to reduce the height and enable the expandable code block#generic
#a11y
language
prop)General checklist
Checked in both light and dark modesChecked in mobileAdded documentationProps have proper autodocs (using(https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/documenting/playgrounds.md)**@default
if default values are missing) and **[playground toggles]Checked Code Sandbox works for any docs examplesUpdated visual regression testsIf applicable, added the breaking change issue label (and filled out the breaking change checklist)If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)