Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(accessibility): apply accessibility handlers with applyAccessibilityKeyHandlers() #1072

Merged
merged 8 commits into from
Mar 20, 2019

Conversation

layershifter
Copy link
Member

Fixes #799.

@layershifter
Copy link
Member Author

layershifter commented Mar 19, 2019

Option 2: mergeAccessibilityHandlers() / applyAccessibilityHandlers()

Add function that will only merge keyHanders.
UPD, we decided:

{...applyAccessibilityKeyHandlers(
  accessibility.keyHanders.root,
  { onKeyDown: this.handleKeyDown, ...unhandedProps },
)}

@codecov
Copy link

codecov bot commented Mar 19, 2019

Codecov Report

Merging #1072 into master will increase coverage by 0.05%.
The diff coverage is 96.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1072      +/-   ##
==========================================
+ Coverage   81.89%   81.94%   +0.05%     
==========================================
  Files         701      702       +1     
  Lines        8554     8580      +26     
  Branches     1169     1172       +3     
==========================================
+ Hits         7005     7031      +26     
  Misses       1534     1534              
  Partials       15       15
Impacted Files Coverage Δ
packages/react/src/lib/getKeyDownHandlers.ts 100% <ø> (ø) ⬆️
packages/react/src/components/Chat/ChatMessage.tsx 95% <ø> (ø) ⬆️
packages/react/src/components/List/ListItem.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/Chat/Chat.tsx 95.45% <ø> (ø) ⬆️
...ges/react/src/components/RadioGroup/RadioGroup.tsx 95.08% <ø> (ø) ⬆️
...react/src/components/RadioGroup/RadioGroupItem.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/Dialog/Dialog.tsx 33.33% <ø> (ø) ⬆️
packages/react/src/components/List/List.tsx 70.83% <ø> (ø) ⬆️
packages/react/src/components/Popup/Popup.tsx 76.26% <ø> (ø) ⬆️
packages/react/src/components/Menu/MenuItem.tsx 63.11% <ø> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d83b722...e05c987. Read the comment docs.

…x/acc-prop

# Conflicts:
#	packages/react/src/components/RadioGroup/RadioGroupItem.tsx
@@ -57,8 +54,6 @@ const getKeyDownHandlers = (

eventHandler && eventHandler(event)
})

_.invoke(props, 'onKeyDown', event, props)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is wrong because it will be applied to each slot, see mini repro:
https://codesandbox.io/s/3kplmnz95q?module=/example.js
When you will click Enter on dots, you will key onKeyDown twice

@layershifter layershifter changed the title fix(accessibility): apply accessibility attributes with mergeAccessibilityProps() fix(accessibility): apply accessibility handlers with applyAccessibilityKeyHandlers() Mar 19, 2019
@layershifter layershifter added 🚀 ready for review 🧰 fix Introduces fix for broken behavior. and removed 🚧 WIP labels Mar 19, 2019
import { Props } from '../types'
import { KeyboardHandler, OnKeyDownHandler } from './accessibility/types'

const applyAccessibilityKeyHandlers = (keyHandlers: OnKeyDownHandler, passedProps: Props) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the second argument really always going to be Props? If we want to use this functionality with the slots as well, should we receive here ShorthandValue? I know that the Popup has special handling of the triggerProps, but usually this is not the case...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, it makes sense because we also deal with slots 👍

keyHandlers: OnKeyDownHandler,
value: Props | ShorthandValue,
) => {
const slotProps: Props = typeof value === 'object' ? value : {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not ignore the other cases of shorthand value. Let's refactor this in the same way it is done in the factories, something like:

  const valIsPropsObject = _.isPlainObject(value)
  const valIsReactElement = React.isValidElement(value)

  const slotProps =
    (valIsReactElement && (value as React.ReactElement<Props>).props) ||
    (valIsPropsObject && (value as Props)) ||
    {}

@layershifter layershifter merged commit edb6117 into master Mar 20, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/acc-prop branch March 20, 2019 10:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants