Skip to content

Conversation

@filippovskii09
Copy link

@filippovskii09 filippovskii09 commented Oct 28, 2025

Note

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

Description

This PR introduces significant accessibility (a11y) improvements to the Notification Tray (Sidebar) and its Trigger Button, making the feature fully operable for keyboard-only users.

Key Changes

  • Trigger State

    • The Notification Trigger button now correctly utilizes the aria-expanded attribute to announce its state (open/closed) to assistive technologies.
  • Focus Management

    • When the Notification Tray is opened, focus is now programmatically moved to the first interactive element inside (the "Close" button).
    • Upon closing the tray, focus is reliably returned to the original Notification Trigger button.
  • Managed Keyboard Navigation

    • Improved Tab key behavior when the sidebar is open.
    • Tabbing from the tray's "Close" button now logically guides the user to the main course navigation elements (e.g., "Course Outline" or unit navigation arrows).

Steps to Test

Note: These steps should be performed using the keyboard to verify accessibility.

  1. Create course and open
  2. In course go to any unit and open
  3. From the main content area, press the Tab key repeatedly to navigate through the page's interactive elements.
  4. Continue tabbing until focus lands on the "Notifications" trigger button (the icon, located in the right side).
  5. Press Enter to activate the trigger.
  6. The Notification Tray opens, and your keyboard focus is moved to the "Close" button (the 'X' icon) inside the tray
  7. With focus remaining on the "Close" button, press Enter again to close the tray.
  8. The Notification Tray closes, and your keyboard focus is returned to the "Notifications" trigger button

Before:

2025-10-31.16.00.26.mov

After:

2025-10-30.13.47.42.mov

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 28, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @filippovskii09!

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

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.

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 98.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.26%. Comparing base (52692dc) to head (ca3a43c).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...sidebar/common/hooks/useSidebarFocusAndKeyboard.js 98.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1817      +/-   ##
==========================================
+ Coverage   90.83%   91.26%   +0.43%     
==========================================
  Files         345      350       +5     
  Lines        5791     5872      +81     
  Branches     1380     1393      +13     
==========================================
+ Hits         5260     5359      +99     
+ Misses        512      494      -18     
  Partials       19       19              

☔ 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.

}

// Tab
const courseOutlineTrigger = document.querySelector('#courseOutlineTrigger');
Copy link
Contributor

Choose a reason for hiding this comment

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

[optional]: Maybe it would be better to clarify what exactly this is a sidebar trigger.

Suggested change
const courseOutlineTrigger = document.querySelector('#courseOutlineTrigger');
const courseOutlineSidebarTrigger = document.querySelector('#courseOutlineTrigger');

Copy link
Author

Choose a reason for hiding this comment

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

yes, this naming better, fixed

Comment on lines 99 to 110
const leftArrow = document.querySelector('.previous-button');
if (leftArrow && !leftArrow.disabled) {
event.preventDefault();
leftArrow.focus();
return;
}

const rightArrow = document.querySelector('.next-button');
if (rightArrow && !rightArrow.disabled) {
event.preventDefault();
rightArrow.focus();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[question]: These are two almost identical constructs. Can we create a function for this that would be convenient to reuse here?

Copy link
Author

Choose a reason for hiding this comment

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

thx, create helper function for this, fixed

focusSidebarTriggerBtn();
};

const handleKeyDown = useCallback((event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: I think it's worth adding a meaningful comment here that would describe how the logic of moving focus around the page works and for which elements.

Copy link
Author

Choose a reason for hiding this comment

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

i added describe text for function, please check it

<div className="d-flex align-items-center mb-2">
<strong className="p-2.5 d-inline-block course-sidebar-title">{title}</strong>
{/* TODO: view this title in UI and decide */}
{/* <strong className="p-2.5 d-inline-block course-sidebar-title">{title}</strong> */}
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 these comments?

Copy link
Author

Choose a reason for hiding this comment

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

removed

const newFocusStatus = !isOpenNotificationStatusBar;
setSessionStorage(`notificationTrayFocus.${courseId}`, String(newFocusStatus));

const isNotificationTrayOpen = getSessionStorage(`notificationTrayStatus.${courseId}`) === 'open';
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: I suggest splitting the logic into two PRs:

  1. Improve accessibility issues
  2. Fix bug with storing sidebar state with notifications

Copy link
Author

Choose a reason for hiding this comment

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

ok, i removed Fixes for storing sidebar state

Copy link
Contributor

Choose a reason for hiding this comment

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

PR for storing sidebar state: #1823

Copy link
Author

@filippovskii09 filippovskii09 Oct 29, 2025

Choose a reason for hiding this comment

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

i added this custom hook useSidebarFocusAndKeyboard.js to separate the logic which we added in this PR
because a lot of logic interfered with orientation in the component

Comment on lines 1 to 2
import { renderHook, act } from '@testing-library/react';
import SidebarContext from '../../SidebarContext';
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 { renderHook, act } from '@testing-library/react';
import SidebarContext from '../../SidebarContext';
import { renderHook, act } from '@testing-library/react';
import SidebarContext from '../../SidebarContext';

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.

Resolved

@@ -0,0 +1,152 @@
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.

removed

Comment on lines 2 to 3
import { Factory } from 'rosie';
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

[code style]: Let’s separate external library imports from local imports with a blank line for better readability.

Suggested change
import { Factory } from 'rosie';
import {
import { Factory } from 'rosie';
import {

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.

Should the line import { createRef } from 'react'; come before import { Factory } from 'rosie';? The idea is to separate library imports from local imports.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 7 to 8
import { Factory } from 'rosie';
import messages from '../../../messages';
Copy link
Contributor

Choose a reason for hiding this comment

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

[question]: Does it make sense to use aliases here?

Suggested change
import { Factory } from 'rosie';
import messages from '../../../messages';
import { Factory } from 'rosie';
import messages from '../../../messages';

Copy link
Author

Choose a reason for hiding this comment

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

fixed

import PropTypes from 'prop-types';
import { Factory } from 'rosie';

import messages from '../../../messages';
Copy link
Contributor

Choose a reason for hiding this comment

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

[question]: Does it make sense to use aliases here?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

});

expect(mockToggleSidebar).toHaveBeenCalledWith(null);
act(() => { jest.runAllTimers(); });
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
act(() => { jest.runAllTimers(); });
act(() => jest.runAllTimers());

Copy link
Author

Choose a reason for hiding this comment

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

fixed


const mockUseSidebarFocusAndKeyboard = useSidebarFocusAndKeyboard;

describe('SidebarBase (Refactored)', () => {
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
describe('SidebarBase (Refactored)', () => {
describe('SidebarBase', () => {

Copy link
Author

Choose a reason for hiding this comment

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

fixed

}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sidebarId, toggleSidebar]);
}, [toggleSidebar]);
Copy link
Contributor

Choose a reason for hiding this comment

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

[clarify]: Is there any reason why sidebarId was removed from deps? Also, do I need to remove // ​​eslint-disable-next-line react-hooks/exhaustive-deps?

Copy link
Author

Choose a reason for hiding this comment

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

no reason, removed

Copy link
Contributor

Choose a reason for hiding this comment

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

My question is related to the fact that sidebarId was previously included in the dependency array. Why was it removed?

Copy link
Author

Choose a reason for hiding this comment

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

because sidebarId it was an unnecessary dependency

const triggerButton = screen.getByRole('button', {
name: messages.openNotificationTrigger.defaultMessage,
});
fireEvent.click(triggerButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets 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.

fixed

sectionId: 'block-v1:edX+DemoX+Demo_Course+type@chapter+block@interactive_demonstrations',
sequenceId: 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@basic_questions',

currentSequence: 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@basic_questions',
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious. Why was this change only added now?

Copy link
Author

Choose a reason for hiding this comment

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

my mistake, removed

@filippovskii09 filippovskii09 force-pushed the filippovskii/feat/course-unit-notifications-tray branch from 47e07d5 to 217a46c Compare October 30, 2025 14:43
@PKulkoRaccoonGang PKulkoRaccoonGang added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Oct 31, 2025
import { tryFocusAndPreventDefault } from '../../utils';
import SidebarContext from '../../SidebarContext';

export const useSidebarFocusAndKeyboard = (sidebarId, triggerButtonSelector = '.sidebar-trigger-btn') => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolved

Comment on lines 1 to 2
import { renderHook, act } from '@testing-library/react';
import SidebarContext from '../../SidebarContext';
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolved

Comment on lines 2 to 3
import { Factory } from 'rosie';
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the line import { createRef } from 'react'; come before import { Factory } from 'rosie';? The idea is to separate library imports from local imports.


it('should hide title bar when showTitleBar prop is false', () => {
renderSidebar({ currentSidebar: SIDEBAR_ID }, { showTitleBar: false });
expect(screen.queryByText('Test Sidebar Title')).not.toBeInTheDocument();
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 replace the static text in these tests with values ​​from defaultProps?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sidebarId, toggleSidebar]);
}, [toggleSidebar]);
Copy link
Contributor

Choose a reason for hiding this comment

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

My question is related to the fact that sidebarId was previously included in the dependency array. Why was it removed?

Comment on lines 7 to 8
import { Factory } from 'rosie';
import messages from '@src/courseware/course/messages';
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 { Factory } from 'rosie';
import messages from '@src/courseware/course/messages';
import { Factory } from 'rosie';
import messages from '@src/courseware/course/messages';

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,9 @@
export const tryFocusAndPreventDefault = (event, selector) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolved

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@itsjeyd
Copy link

itsjeyd commented Nov 6, 2025

Hey @PKulkoRaccoonGang, am I right in assuming that this is another PR you'll add when you create your product proposal for a11y improvements?

@itsjeyd itsjeyd moved this from Needs Triage to Waiting on Author in Contributions Nov 6, 2025
@itsjeyd itsjeyd added the product review PR requires product review before merging label Nov 6, 2025

mockQuerySelector = jest.spyOn(document, 'querySelector');
mockQuerySelector.mockImplementation((selector) => {
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
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
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
if (selector === TRIGGER_SELECTOR) {
return triggerButtonMock;
}

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 177 to 179
if (selector === '#courseOutlineSidebarTrigger') { return mockOutlineTrigger; }
if (selector === '.previous-button') { return mockPrevButton; }
if (selector === '.next-button') { return mockNextButton; }
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
if (selector === '#courseOutlineSidebarTrigger') { return mockOutlineTrigger; }
if (selector === '.previous-button') { return mockPrevButton; }
if (selector === '.next-button') { return mockNextButton; }
if (selector === '#courseOutlineSidebarTrigger') {
return mockOutlineTrigger;
}
if (selector === '.previous-button') {
return mockPrevButton;
}
if (selector === '.next-button') {
return mockNextButton;
}

Copy link
Author

Choose a reason for hiding this comment

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

fixed

const { result } = renderHookWithContext(mockContextValue);

mockQuerySelector.mockImplementation((selector) => {
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
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
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
if (selector === TRIGGER_SELECTOR) {
return triggerButtonMock;
}

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 223 to 224
if (selector === '.call-to-action-btn') { return mockCtaButton; }
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
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
if (selector === '.call-to-action-btn') { return mockCtaButton; }
if (selector === TRIGGER_SELECTOR) { return triggerButtonMock; }
if (selector === '.call-to-action-btn') {
return mockCtaButton;
}
if (selector === TRIGGER_SELECTOR) {
return triggerButtonMock;
}

Copy link
Author

Choose a reason for hiding this comment

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

fixed

sidebarTriggerBtnRef.current?.blur();
sidebarTriggerBtnRef.current?.blur();

sidebarTriggerBtnRef.current?.blur();
Copy link
Contributor

Choose a reason for hiding this comment

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

[clarify]: Do we need to add blur to sidebarTriggerBtnRef three times here?

Copy link
Author

Choose a reason for hiding this comment

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

removed extra lines

@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

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 product review PR requires product review before merging

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

5 participants