-
Notifications
You must be signed in to change notification settings - Fork 297
feat: improved accessibility of notification tray #1817
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
220d14e
c6fc88b
8eb8ab0
5199cee
217a46c
d23f8a2
ca3a43c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,12 @@ import { Icon, IconButton } from '@openedx/paragon'; | |||||
| import { ArrowBackIos, Close } from '@openedx/paragon/icons'; | ||||||
| import classNames from 'classnames'; | ||||||
| import PropTypes from 'prop-types'; | ||||||
| import { useCallback, useContext } from 'react'; | ||||||
| import { | ||||||
| useCallback, useContext, useEffect, useRef, | ||||||
| } from 'react'; | ||||||
|
|
||||||
| import { useEventListener } from '@src/generic/hooks'; | ||||||
| import { setSessionStorage, getSessionStorage } from '@src/data/sessionStorage'; | ||||||
| import messages from '../../messages'; | ||||||
| import SidebarContext from '../SidebarContext'; | ||||||
|
|
||||||
|
|
@@ -19,21 +23,127 @@ const SidebarBase = ({ | |||||
| }) => { | ||||||
| const intl = useIntl(); | ||||||
| const { | ||||||
| courseId, | ||||||
| toggleSidebar, | ||||||
| shouldDisplayFullScreen, | ||||||
| currentSidebar, | ||||||
| } = useContext(SidebarContext); | ||||||
|
|
||||||
| const closeBtnRef = useRef(null); | ||||||
| const responsiveCloseNotificationTrayRef = useRef(null); | ||||||
| const isOpenNotificationTray = getSessionStorage(`notificationTrayStatus.${courseId}`) === 'open'; | ||||||
| const isFocusedNotificationTray = getSessionStorage(`notificationTrayFocus.${courseId}`) === 'true'; | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| if (isOpenNotificationTray && isFocusedNotificationTray && closeBtnRef.current) { | ||||||
| closeBtnRef.current.focus(); | ||||||
| } | ||||||
|
|
||||||
| if (shouldDisplayFullScreen) { | ||||||
| responsiveCloseNotificationTrayRef.current?.focus(); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| const receiveMessage = useCallback(({ data }) => { | ||||||
| const { type } = data; | ||||||
| if (type === 'learning.events.sidebar.close') { | ||||||
| toggleSidebar(null); | ||||||
| } | ||||||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||||||
| }, [sidebarId, toggleSidebar]); | ||||||
| }, [toggleSidebar]); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no reason, removed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question is related to the fact that
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because |
||||||
|
|
||||||
| useEventListener('message', receiveMessage); | ||||||
|
|
||||||
| const focusSidebarTriggerBtn = () => { | ||||||
| const performFocus = () => { | ||||||
| const sidebarTriggerBtn = document.querySelector('.sidebar-trigger-btn'); | ||||||
| if (sidebarTriggerBtn) { | ||||||
| sidebarTriggerBtn.focus(); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| requestAnimationFrame(() => { | ||||||
| requestAnimationFrame(performFocus); | ||||||
| }); | ||||||
| }; | ||||||
|
|
||||||
| const handleCloseNotificationTray = () => { | ||||||
| toggleSidebar(null); | ||||||
| setSessionStorage(`notificationTrayFocus.${courseId}`, 'true'); | ||||||
| setSessionStorage(`notificationTrayStatus.${courseId}`, 'closed'); | ||||||
| focusSidebarTriggerBtn(); | ||||||
| }; | ||||||
|
|
||||||
| const handleKeyDown = useCallback((event) => { | ||||||
|
||||||
| const { key, shiftKey, target } = event; | ||||||
|
|
||||||
| if (key !== 'Tab' || target !== closeBtnRef.current) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Shift + Tab | ||||||
| if (shiftKey) { | ||||||
| event.preventDefault(); | ||||||
| focusSidebarTriggerBtn(); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Tab | ||||||
| const courseOutlineTrigger = document.querySelector('#courseOutlineTrigger'); | ||||||
|
||||||
| const courseOutlineTrigger = document.querySelector('#courseOutlineTrigger'); | |
| const courseOutlineSidebarTrigger = document.querySelector('#courseOutlineTrigger'); |
There was a problem hiding this comment.
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
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,37 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
| import { forwardRef } from 'react'; | ||
|
|
||
| const SidebarTriggerBase = ({ | ||
| const SidebarTriggerBase = forwardRef(({ | ||
| onClick, | ||
| onKeyDown, | ||
| ariaLabel, | ||
| children, | ||
| }) => ( | ||
| isOpenNotificationStatusBar, | ||
| sectionId, | ||
| }, ref) => ( | ||
| <button | ||
| className="border border-light-400 bg-transparent align-items-center align-content-center d-flex notification-btn" | ||
| className="border border-light-400 bg-transparent align-items-center align-content-center d-flex notification-btn sidebar-trigger-btn" | ||
| type="button" | ||
| onClick={onClick} | ||
| onKeyDown={onKeyDown} | ||
| aria-label={ariaLabel} | ||
| aria-expanded={isOpenNotificationStatusBar} | ||
| aria-controls={sectionId} | ||
| ref={ref} | ||
| > | ||
| <div className="icon-container d-flex position-relative align-items-center"> | ||
| {children} | ||
| </div> | ||
| </button> | ||
| ); | ||
| )); | ||
|
|
||
| SidebarTriggerBase.propTypes = { | ||
| onClick: PropTypes.func.isRequired, | ||
| onKeyDown: PropTypes.func.isRequired, | ||
| ariaLabel: PropTypes.string.isRequired, | ||
| children: PropTypes.element.isRequired, | ||
| isOpenNotificationStatusBar: PropTypes.bool.isRequired, | ||
| sectionId: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| export default SidebarTriggerBase; |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,8 +4,8 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | |||||||||||
| import { breakpoints } from '@openedx/paragon'; | ||||||||||||
|
|
||||||||||||
| import MockAdapter from 'axios-mock-adapter'; | ||||||||||||
| import React from 'react'; | ||||||||||||
| import { Factory } from 'rosie'; | ||||||||||||
| import messages from '../../../messages'; | ||||||||||||
|
||||||||||||
| import { Factory } from 'rosie'; | |
| import messages from '../../../messages'; | |
| import { Factory } from 'rosie'; | |
| import messages from '../../../messages'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my mistake, removed