-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Mobile: Accessibility: Improve focus handling in the note actions menu and modal dialogs #11929
Open
personalizedrefrigerator
wants to merge
15
commits into
laurent22:dev
Choose a base branch
from
personalizedrefrigerator:pr/mobile/improve-focus
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
85c9f57
Mobile: Accessibility: Improve focus behavior for new note menu and
personalizedrefrigerator a9b68f4
Add onAccessibilityEscape to the note actions menu
personalizedrefrigerator 9d893f5
Fix rendering on Android
personalizedrefrigerator d2779a7
Improve autofocus behavior when dismissing dialogs
personalizedrefrigerator b749688
Refactoring
personalizedrefrigerator 204730f
Fix tests
personalizedrefrigerator efcb6ee
Fix autofocus callback not set correctly
personalizedrefrigerator 1346377
Android: Possible fix for focus not jumping to autofocus items after
personalizedrefrigerator 51237ca
Fix new refocus logic breaks native refocus logic
personalizedrefrigerator 273c3cd
Revert unnecessary change
personalizedrefrigerator b5507dc
More consistent naming
personalizedrefrigerator 7ffa4c9
Technical spec
personalizedrefrigerator 3bdc6e5
Reword technical spec
personalizedrefrigerator c07e4b0
Add reason for naming
personalizedrefrigerator ba30ffb
Fix main content not correctly resizing on Android
personalizedrefrigerator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/app-mobile/components/accessibility/AccessibleView.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as React from 'react'; | ||
import FocusControl from './FocusControl/FocusControl'; | ||
import { render } from '@testing-library/react-native'; | ||
import AccessibleView from './AccessibleView'; | ||
import { AccessibilityInfo } from 'react-native'; | ||
import ModalWrapper from './FocusControl/ModalWrapper'; | ||
import { ModalState } from './FocusControl/types'; | ||
|
||
interface TestContentWrapperProps { | ||
mainContent: React.ReactNode; | ||
dialogs: React.ReactNode; | ||
} | ||
|
||
const TestContentWrapper: React.FC<TestContentWrapperProps> = props => { | ||
return <FocusControl.Provider> | ||
{props.dialogs} | ||
<FocusControl.MainAppContent> | ||
{props.mainContent} | ||
</FocusControl.MainAppContent> | ||
</FocusControl.Provider>; | ||
}; | ||
|
||
jest.mock('react-native', () => { | ||
const ReactNative = jest.requireActual('react-native'); | ||
ReactNative.AccessibilityInfo.setAccessibilityFocus = jest.fn(); | ||
return ReactNative; | ||
}); | ||
|
||
describe('AccessibleView', () => { | ||
test('should wait for the currently-open dialog to dismiss before applying focus requests', () => { | ||
const setFocusMock = AccessibilityInfo.setAccessibilityFocus as jest.Mock; | ||
setFocusMock.mockClear(); | ||
|
||
interface TestContentOptions { | ||
modalState: ModalState; | ||
refocusCounter: undefined|number; | ||
} | ||
const renderTestContent = ({ modalState, refocusCounter }: TestContentOptions) => { | ||
const mainContent = <AccessibleView refocusCounter={refocusCounter}/>; | ||
const visibleDialog = <ModalWrapper state={modalState}>{null}</ModalWrapper>; | ||
return <TestContentWrapper | ||
mainContent={mainContent} | ||
dialogs={visibleDialog} | ||
/>; | ||
}; | ||
|
||
render(renderTestContent({ | ||
refocusCounter: undefined, | ||
modalState: ModalState.Open, | ||
})); | ||
|
||
// Increasing the refocusCounter for a background view while a dialog is visible | ||
// should not try to focus the background view. | ||
render(renderTestContent({ | ||
refocusCounter: 1, | ||
modalState: ModalState.Open, | ||
})); | ||
expect(setFocusMock).not.toHaveBeenCalled(); | ||
|
||
// Focus should not be set until done closing | ||
render(renderTestContent({ | ||
refocusCounter: 1, | ||
modalState: ModalState.Closing, | ||
})); | ||
expect(setFocusMock).not.toHaveBeenCalled(); | ||
|
||
// Keeping the same refocus counter, but dismissing the dialog should focus | ||
// the test view. | ||
render(renderTestContent({ | ||
refocusCounter: 1, | ||
modalState: ModalState.Closed, | ||
})); | ||
expect(setFocusMock).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently,
testID
, if provided, is included in thefocus
log message. It may make sense to use a different prop for this (e.g.debugTag
) and make it required ifrefocusCounter
is specified.