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

[EuiContextMenuItem] Added an example aria-current attribute and documentation for a11y #7153

Merged
merged 8 commits into from
Sep 11, 2023

Conversation

1Copenut
Copy link
Contributor

@1Copenut 1Copenut commented Sep 1, 2023

Summary

The EuiContextMenu has an option to create a single panel menu where one item can be selected. I added an aria-current="true" to the example views and updated the local state handler function and documentation.

This PR closes #6648

QA

Remove or strikethrough items that do not apply to your PR.

General checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

* WIP. Tried out using an isCurrent boolean prop.
* Refactored icon check to set aria-current also.
* Removed isCurrent prop because aria-current is state not handed down from parent.
@1Copenut 1Copenut self-assigned this Sep 1, 2023
@1Copenut 1Copenut marked this pull request as ready for review September 1, 2023 20:14
Comment on lines 27 to 36
const getCurrentItem = (size, attr) => {
if (attr === 'icon') {
return size === rowSize ? 'check' : 'empty';
}

if (attr === 'aria-current') {
return size === rowSize ? 'true' : undefined;
}

return undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went this direction after looking at the EuiContextMenuPanel and EuiContextMenuItem for an hour or so. I didn't see a relationship between the two for state management on single panel menus. The panel component checked for an array of items and then created the child components and rendered them.

Looking at the docs, I saw an opportunity to use the local state management function and extend it. This approach does leave it on the consumer to add an aria-current attribute, but doesn't degrade the screen reader UX by setting a default selected item and not having it get updated.

Copy link
Member

@cee-chen cee-chen Sep 6, 2023

Choose a reason for hiding this comment

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

I think there's a cleaner way this could be written. Try this:

const isSelectedProps = (size: number) => {
  return size === rowSize
    ? { icon: 'checked', 'aria-current': true }
    : { icon: 'empty', 'aria-current': undefined };
};

<EuiContextMenuItem
  {...isSelectedProps(10)}
  key="10 rows"
  // ...
>

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, just realized I didn't address your first paragraph - you're right on this being a docs/example only change and not making this change opinionatedly in EuiContextMenuItem's source code. EuiTablePagination on the other hand should have an actual source code change.

title="The selected context menu item should have an aria-current attribute"
>
<p>
<strong>aria-current</strong> tells screen readers which item is
Copy link
Member

Choose a reason for hiding this comment

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

Just curious - what meaningful or semantic difference is there between aria-current and aria-pressed for this use case?

Copy link
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 subtle distinction, but I went with aria-current="true" because it announced the page as Page 1, current button in screen readers. This felt like a natural, concise UX.

I also looked at MDN for their definitions of aria-pressed and aria-current:

aria-current="true"
Represents the current item within a set.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current

aria-pressed="true"
The button is pressed.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks for the explanation! 🎉

@1Copenut 1Copenut added skip-changelog documentation Issues or PRs that only affect documentation - will not need changelog entries labels Sep 11, 2023
Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Changes LGTM!

src-docs/src/views/context_menu/context_menu_example.js Outdated Show resolved Hide resolved
@1Copenut 1Copenut enabled auto-merge (squash) September 11, 2023 16:19
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7153/

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @1Copenut

@1Copenut 1Copenut merged commit 7cf33bd into elastic:main Sep 11, 2023
7 checks passed
@1Copenut 1Copenut deleted the feature/euiContextMenu-sr-choice branch September 11, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility documentation Issues or PRs that only affect documentation - will not need changelog entries skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiContextMenu][SCREEN READER]: Add prop to announce selected item on single choice panels like pagination
4 participants