Skip to content

Conversation

@filippovskii09
Copy link

@filippovskii09 filippovskii09 commented Nov 5, 2025

Note

This PR will be added to the product proposal to improve accessibility.

Description

Improving the accessibility of a user dropdown menu.

Key changes:

  • Implemented a focus trap so the Tab and arrow keys are contained within the menu until it is closed.
  • Focus is now automatically placed on the first item when the menu is opened.
  • Added role="menu" to the menu container.
  • Added role="menuitem" to each item within the menu.
  • Added an accessible name to the menu's trigger button using the aria-label attribute.

Testing instructions

Steps to reproduce:

  1. Create a new course.
  2. Go to the Home page.
  3. Using Tab key go to dropdown menu and click Enter
  4. Ensure tab and arrow keys are trapped in the menu until it is closed.
  5. Ensure all tags has necessary attributes
  6. Ensure everything works correctly for mobile device screens.
2025-11-05.17.58.03.mov

@filippovskii09 filippovskii09 self-assigned this Nov 5, 2025
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 5, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @filippovskii09!

This repository is currently maintained by @openedx/committers-frontend.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If 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 PR

Your 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Nov 5, 2025
@filippovskii09 filippovskii09 added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.76%. Comparing base (9706385) to head (cc886b5).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #653      +/-   ##
==========================================
+ Coverage   72.11%   73.76%   +1.65%     
==========================================
  Files          55       56       +1     
  Lines         502      526      +24     
  Branches      108      117       +9     
==========================================
+ Hits          362      388      +26     
+ Misses        137      136       -1     
+ Partials        3        2       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@filippovskii09 filippovskii09 force-pushed the filippovskii/feat/header-dropdown-btn-label branch from ece7ac2 to f335bc4 Compare November 5, 2025 16:23
@PKulkoRaccoonGang PKulkoRaccoonGang added create-sandbox open-craft-grove should create a sandbox environment from this PR and removed create-sandbox open-craft-grove should create a sandbox environment from this PR labels Nov 6, 2025
@@ -0,0 +1,91 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this React import?

Copy link
Author

Choose a reason for hiding this comment

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

if we remove this somewhere, errors will occur

renderComponent();

const toggleButton = screen.getByRole('button', { name: 'User Options' });
await fireEvent.click(toggleButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use userEvent

Copy link
Author

Choose a reason for hiding this comment

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

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' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use translations instead of hardcoded text?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

renderComponent();

const toggleButton = screen.getByRole('button', { name: 'User Options' });
await fireEvent.click(toggleButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use userEvent

Copy link
Author

Choose a reason for hiding this comment

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

userEvent package does not use in this header-component

renderComponent();

const toggleButton = screen.getByRole('button', { name: 'User Options' });
await fireEvent.click(toggleButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use userEvent

Copy link
Author

Choose a reason for hiding this comment

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

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}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rewrite this to get rid of // eslint-disable-next-line no-nested-ternary and make the code clearer?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

lastMenuItemRef,
}) => items.map((item, index) => (
<Dropdown.Item
href={item.href}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add a key to Dropdown.Item?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding these variables?

Copy link
Author

@filippovskii09 filippovskii09 Nov 9, 2025

Choose a reason for hiding this comment

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

becouse we used this vars there AuthenticatedUserDropdown.test.jsx and need to mock it

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 6, 2025
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' });
Copy link
Contributor

Choose a reason for hiding this comment

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

it('focuses next link when Tab is pressed on middle item', async () => {
renderComponent();

const toggleButton = screen.getByRole('button', { name: 'User Options' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +1 to +6
import React from 'react';
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown';
import messages from './messages';
import {
render, screen, fireEvent, initializeMockApp,
} from '../setupTest';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.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}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', process.env.LOGOUT_URL);
expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', getConfig().LOGOUT_URL);

Comment on lines +12 to +16
const getRefForIndex = (index, length) => {
if (index === 0) { return firstMenuItemRef; }
if (index === length - 1) { return lastMenuItemRef; }
return null;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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;
};

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

Labels

create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

3 participants