This repository was archived by the owner on Mar 4, 2020. It is now read-only.
fix(Accessibility): fix order of applying unhandled props and key handlers#1901
Merged
jurokapsiar merged 7 commits intomasterfrom Sep 11, 2019
Merged
fix(Accessibility): fix order of applying unhandled props and key handlers#1901jurokapsiar merged 7 commits intomasterfrom
jurokapsiar merged 7 commits intomasterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1901 +/- ##
==========================================
+ Coverage 69.9% 69.97% +0.06%
==========================================
Files 894 895 +1
Lines 7796 7814 +18
Branches 2251 2281 +30
==========================================
+ Hits 5450 5468 +18
Misses 2336 2336
Partials 10 10
Continue to review full report at Codecov.
|
layershifter
reviewed
Sep 9, 2019
Member
layershifter
left a comment
There was a problem hiding this comment.
- Let's add an entry to CHANGELOG
- Let's add a proper UT, may be it will catch additional cases (under
isConformant):
test(`handles "onKeyDown" overrides`, () => {
const actionHandler = jest.fn()
const eventHandler = jest.fn()
const actionBehavior: Accessibility = () => ({
keyActions: {
root: {
mockAction: {
keyCombinations: [{ keyCode: keyboardKey.Enter }],
},
},
},
})
const wrapperProps = {
...requiredProps,
accessibility: actionBehavior,
'data-simulate-event-here': true,
onKeyDown: eventHandler,
}
const wrapper = mount(<Component {...wrapperProps} />)
;(wrapper.instance() as UIComponent<any, any>).actionHandlers.mockAction = actionHandler
// Force render component to apply updated key handlers
wrapper.setProps({})
getEventTargetComponent(wrapper, 'onKeyDown').simulate(
'keydown',
{ keyCode: keyboardKey.Enter },
)
expect(actionHandler).toBeCalledTimes(1)
expect(eventHandler).toBeCalledTimes(1)
})
layershifter
approved these changes
Sep 9, 2019
Member
layershifter
left a comment
There was a problem hiding this comment.
Please fix CI before merge 🚀
mnajdova
reviewed
Sep 10, 2019
| {...accessibility.attributes.root} | ||
| {...applyAccessibilityKeyHandlers(accessibility.keyHandlers.root, unhandledProps)} | ||
| {...unhandledProps} | ||
| {...applyAccessibilityKeyHandlers(accessibility.keyHandlers.root, unhandledProps)} |
Contributor
There was a problem hiding this comment.
This is correct applyAccessibilityKeyHandlers should always be spread after the unhandledProps, as it will invoke the key events provided by the behavior.
Contributor
Author
There was a problem hiding this comment.
yes, there's now even a test verifying that for all compoennts (that have the actions defined)
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #1899
Key handlers need to be applied after unhandled props so that onKeyDown is not overwritten but correctly respects both the key handlers from behaviors as well as onKeyDown passed by the consumer or by a wrapping component (popup)