Skip to content

Accessibility fixes for copy button#313

Open
ahamelers wants to merge 3 commits into
Authress-Engineering:release/2.4from
ahamelers:accessibility/copy-button
Open

Accessibility fixes for copy button#313
ahamelers wants to merge 3 commits into
Authress-Engineering:release/2.4from
ahamelers:accessibility/copy-button

Conversation

@ahamelers

Copy link
Copy Markdown
Contributor

Currently, there are several accessibility issues with the copy button:

  1. The function works in such a way that the focus is removed from the button, stranding the keyboard/screen reading user
  2. If there are multiple copy buttons on the same page, they all have the same text and so cannot be discerned from one another by the screen reader user
  3. The 'copied' success status update is not announced to the screen reader user.

This PR fixes these issues by:

  1. Updating the copy function to use the clipboard API and no longer change focus
  2. Adding an aria-label to each copy button to make it clear to the screen reader user what they are copying
  3. Updating the label and adding an aria-live setting to the button so the 'copied' success status update is announced

Also note that scrollable regions on a page must be able to receive tab focus, and stuff that's focussable should be labeled and given a role if possible, so this PR also adds a label, role, and tabindex to the scrollable region that the copy button copies.

Comment thread src/components/syntax-highlighter.js Outdated
Comment thread src/utils/common-utils.js
if (btnEl) {
const label = btnEl.getAttribute('aria-label');
btnEl.innerText = getI18nText('operations.copied');
btnEl.setAttribute('aria-label', getI18nText('operations.copied'));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the correct thing to do for a screen reader? Setting the aria-label and changing it? That feels wrong to me, but I don't really understand how aria-labels work. What's your thinking here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit complicated because the button itself contains the status update text for the success ('copied'). We want to let users know the 'copied' success status, so there's an aria-live region on the button. But screen readers will never read the actual content of the button if aria-label is also set, they will always read that instead. So we have to update the aria-label as well for the status to be announced.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refuse to believe this is right way to solve this problem for screen readers. Why would a screen reader announce the button label change?

Multiple llms suggested to me to have a separate hidden div with the text that can be targeted for update instead of this here. Because actually I worry that since we are updating the button text twice which means that it could actually display both the "copied" message and then again the "label" message which not correct.

Is that accurate, IDK, but that feels better than this implementation.

: html`
<div class="tab-content col m-markdown" style="flex:1; display:${this.activeResponseTab === 'response' ? 'flex' : 'none'};" >
<syntax-highlighter style="min-height: 60px" mime-type="${this.responseContentType}" .content="${this.responseText}"/>
<syntax-highlighter style="min-height: 60px" mime-type="${this.responseContentType}" .content="${this.responseText}" .label="Response text"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost forgot, all of these labels need to be i18n keys instead of hard coded text because we support multiple languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants