-
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 2 commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,152 @@ | ||||||||||||
| import React from 'react'; | ||||||||||||
|
||||||||||||
| import { Factory } from 'rosie'; | ||||||||||||
| import { | ||||||||||||
|
Comment on lines
1
to
5
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. [code style]: Let’s separate external library imports from local imports with a blank line for better readability.
Suggested change
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. fixed
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. Should the line
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. fixed |
||||||||||||
| initializeTestStore, | ||||||||||||
| render, | ||||||||||||
| screen, | ||||||||||||
| fireEvent, | ||||||||||||
| waitFor, | ||||||||||||
| } from '@src/setupTest'; | ||||||||||||
| import userEvent from '@testing-library/user-event'; | ||||||||||||
| import SidebarContext from '../SidebarContext'; | ||||||||||||
| import SidebarBase from './SidebarBase'; | ||||||||||||
| import messages from '../../messages'; | ||||||||||||
| import { useSidebarFocusAndKeyboard } from './hooks/useSidebarFocusAndKeyboard'; | ||||||||||||
|
|
||||||||||||
| jest.mock('./hooks/useSidebarFocusAndKeyboard'); | ||||||||||||
|
|
||||||||||||
| const SIDEBAR_ID = 'test-sidebar'; | ||||||||||||
|
|
||||||||||||
| const mockUseSidebarFocusAndKeyboard = useSidebarFocusAndKeyboard; | ||||||||||||
|
|
||||||||||||
| describe('SidebarBase (Refactored)', () => { | ||||||||||||
|
||||||||||||
| describe('SidebarBase (Refactored)', () => { | |
| describe('SidebarBase', () => { |
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
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.
Can we replace the static text in these tests with values from defaultProps?
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,14 @@ 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, | ||
| } from 'react'; | ||
|
|
||
| import { useEventListener } from '@src/generic/hooks'; | ||
| import messages from '../../messages'; | ||
| import SidebarContext from '../SidebarContext'; | ||
| import { useSidebarFocusAndKeyboard } from './hooks/useSidebarFocusAndKeyboard'; | ||
|
|
||
| const SidebarBase = ({ | ||
| title, | ||
|
|
@@ -24,13 +28,23 @@ const SidebarBase = ({ | |
| currentSidebar, | ||
| } = useContext(SidebarContext); | ||
|
|
||
| const { | ||
| closeBtnRef, | ||
| backBtnRef, | ||
| handleClose, | ||
| handleKeyDown, | ||
| handleBackBtnKeyDown, | ||
| } = useSidebarFocusAndKeyboard(sidebarId); | ||
|
|
||
| const isOpen = currentSidebar === sidebarId; | ||
|
|
||
| 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); | ||
|
|
||
|
|
@@ -39,7 +53,7 @@ const SidebarBase = ({ | |
| className={classNames('ml-0 border border-light-400 rounded-sm h-auto align-top zindex-0', { | ||
| 'bg-white m-0 border-0 fixed-top vh-100 rounded-0': shouldDisplayFullScreen, | ||
| 'align-self-start': !shouldDisplayFullScreen, | ||
| 'd-none': currentSidebar !== sidebarId, | ||
| 'd-none': !isOpen, | ||
| }, className)} | ||
| data-testid={`sidebar-${sidebarId}`} | ||
| style={{ width: shouldDisplayFullScreen ? '100%' : width }} | ||
|
|
@@ -49,9 +63,10 @@ const SidebarBase = ({ | |
| {shouldDisplayFullScreen ? ( | ||
| <div | ||
| className="pt-2 pb-2.5 border-bottom border-light-400 d-flex align-items-center ml-2" | ||
| onClick={() => toggleSidebar(null)} | ||
| onKeyDown={() => toggleSidebar(null)} | ||
| onClick={handleClose} | ||
| onKeyDown={handleBackBtnKeyDown} | ||
| role="button" | ||
| ref={backBtnRef} | ||
| tabIndex="0" | ||
| > | ||
| <Icon src={ArrowBackIos} /> | ||
|
|
@@ -63,16 +78,19 @@ const SidebarBase = ({ | |
| {showTitleBar && ( | ||
| <> | ||
| <div className="d-flex align-items-center mb-2"> | ||
| <strong className="p-2.5 d-inline-block course-sidebar-title">{title}</strong> | ||
| <h2 className="p-2.5 d-inline-block m-0 text-gray-700 h4">{title}</h2> | ||
| {shouldDisplayFullScreen | ||
| ? null | ||
| : ( | ||
| <div className="d-inline-flex mr-2 ml-auto"> | ||
| <IconButton | ||
| className="sidebar-close-btn" | ||
| src={Close} | ||
| size="sm" | ||
| ref={closeBtnRef} | ||
| iconAs={Icon} | ||
| onClick={() => toggleSidebar(null)} | ||
| onClick={handleClose} | ||
| onKeyDown={handleKeyDown} | ||
| variant="primary" | ||
| alt={intl.formatMessage(messages.closeNotificationTrigger)} | ||
| /> | ||
|
|
||
| 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; |
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