feat: improved accessibility of learning header#653
feat: improved accessibility of learning header#653filippovskii09 wants to merge 4 commits intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @filippovskii09! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #653 +/- ##
==========================================
+ Coverage 72.11% 73.86% +1.75%
==========================================
Files 55 56 +1
Lines 502 528 +26
Branches 108 117 +9
==========================================
+ Hits 362 390 +28
+ Misses 137 136 -1
+ Partials 3 2 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ece7ac2 to
f335bc4
Compare
| @@ -0,0 +1,91 @@ | |||
| import React from 'react'; | |||
There was a problem hiding this comment.
Do we need this React import?
There was a problem hiding this comment.
if we remove this somewhere, errors will occur
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); | ||
| await fireEvent.click(toggleButton); |
There was a problem hiding this comment.
Let's use userEvent
There was a problem hiding this comment.
userEvent package does not use in this header-component
| it('loops focus from last to first and vice versa with Tab and Shift+Tab', async () => { | ||
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); |
There was a problem hiding this comment.
Can we use translations instead of hardcoded text?
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); | ||
| await fireEvent.click(toggleButton); |
There was a problem hiding this comment.
Let's use userEvent
There was a problem hiding this comment.
userEvent package does not use in this header-component
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); | ||
| await fireEvent.click(toggleButton); |
There was a problem hiding this comment.
Let's use userEvent
There was a problem hiding this comment.
userEvent package does not use in this header-component
| role="menuitem" | ||
| onKeyDown={handleKeyDown} | ||
| // eslint-disable-next-line no-nested-ternary | ||
| ref={index === 0 ? firstMenuItemRef : index === items.length - 1 ? lastMenuItemRef : null} |
There was a problem hiding this comment.
Can we rewrite this to get rid of // eslint-disable-next-line no-nested-ternary and make the code clearer?
| lastMenuItemRef, | ||
| }) => items.map((item, index) => ( | ||
| <Dropdown.Item | ||
| href={item.href} |
There was a problem hiding this comment.
Do we need to add a key to Dropdown.Item?
| ACCOUNT_SETTINGS_URL: process.env.ACCOUNT_SETTINGS_URL || null, | ||
| ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL || null, | ||
| ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL || null, | ||
| CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL || null, |
There was a problem hiding this comment.
Why are we adding these variables?
There was a problem hiding this comment.
becouse we used this vars there AuthenticatedUserDropdown.test.jsx and need to mock it
| it('loops focus from last to first and vice versa with Tab and Shift+Tab', async () => { | ||
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); |
| it('focuses next link when Tab is pressed on middle item', async () => { | ||
| renderComponent(); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); |
| import React from 'react'; | ||
| import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; | ||
| import messages from './messages'; | ||
| import { | ||
| render, screen, fireEvent, initializeMockApp, | ||
| } from '../setupTest'; |
There was a problem hiding this comment.
| import React from 'react'; | |
| import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; | |
| import messages from './messages'; | |
| import { | |
| render, screen, fireEvent, initializeMockApp, | |
| } from '../setupTest'; | |
| import React from 'react'; | |
| import { | |
| render, screen, fireEvent, initializeMockApp, | |
| } from '../setupTest'; | |
| import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; | |
| import messages from './messages'; |
| await fireEvent.click(toggleButton); | ||
|
|
||
| expect(await screen.findByText(messages.dashboard.defaultMessage)) | ||
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); |
There was a problem hiding this comment.
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); | |
| .toHaveAttribute('href', `${getConfig().LMS_BASE_URL}/dashboard`); |
| expect(await screen.findByText(messages.dashboard.defaultMessage)) | ||
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); | ||
|
|
||
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); |
There was a problem hiding this comment.
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | |
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`); |
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); | ||
|
|
||
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | ||
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); |
There was a problem hiding this comment.
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); | |
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', getConfig().ACCOUNT_SETTINGS_URL); |
|
|
||
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | ||
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); | ||
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', process.env.ORDER_HISTORY_URL); |
There was a problem hiding this comment.
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', process.env.ORDER_HISTORY_URL); | |
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', getConfig().ORDER_HISTORY_URL); |
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | ||
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); | ||
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', process.env.ORDER_HISTORY_URL); | ||
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', process.env.LOGOUT_URL); |
There was a problem hiding this comment.
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', process.env.LOGOUT_URL); | |
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', getConfig().LOGOUT_URL); |
| const getRefForIndex = (index, length) => { | ||
| if (index === 0) { return firstMenuItemRef; } | ||
| if (index === length - 1) { return lastMenuItemRef; } | ||
| return null; | ||
| }; |
There was a problem hiding this comment.
| const getRefForIndex = (index, length) => { | |
| if (index === 0) { return firstMenuItemRef; } | |
| if (index === length - 1) { return lastMenuItemRef; } | |
| return null; | |
| }; | |
| const getRefForIndex = (index, length) => { | |
| if (index === 0) { | |
| return firstMenuItemRef; | |
| } | |
| if (index === length - 1) { | |
| return lastMenuItemRef; | |
| } | |
| return null; | |
| }; |
|
OSPR management note: This is part of a larger a11y initative (openedx/platform-roadmap#495), together with seven related PRs against https://github.com/openedx/frontend-app-learning. |
Note
This PR has been added to the product proposal to improve accessibility.
Product proposal
Description
Improving the accessibility of a user dropdown menu.
Key changes:
Taband arrow keys are contained within the menu until it is closed.role="menu"to the menu container.role="menuitem"to each item within the menu.aria-labelattribute.Testing instructions
Steps to reproduce:
2025-11-05.17.58.03.mov