[RFC] feat(Accessibility): Make action handlers conditional based on Event object#1588
[RFC] feat(Accessibility): Make action handlers conditional based on Event object#1588
Conversation
|
This pull request is automatically deployed with Now. Latest deployment for this branch: https://stardust-react-git-feat-conditional-action-handlers.stardust-ui.now.sh |
| shouldHandle: event => !doesEventComesFromChildItem(event), | ||
| }, | ||
| }), | ||
| ...(!isSubtreeOpen(props) && { |
There was a problem hiding this comment.
I am not sure I like the combination of conditionally adding key handlers based on props and conditionally invoking them based on event (and eventually props).
Wouldn't it be easier to switch everything to shouldHandle condition? (I am aware of the fact that this can result in added keyhandlers which never call any action.)
Other opinions?
There was a problem hiding this comment.
@miroslavstastny I totally share your thought, have same concerns.
@kuzhelov @mnajdova @layershifter need your input here
|
|
||
| this.handleTitleClick(e) | ||
| }, | ||
| passFocus: e => { |
There was a problem hiding this comment.
Suggestion: focusSubtree? It would be nice to say where we are passing the focus to. Currently, it says to pass it, but as a dev implementing this I'm not sure where to pass it to.
| /** Checks if current tree item has a subtree and it is opened */ | ||
| const isSubtreeOpen = (props: TreeItemBehaviorProps): boolean => { | ||
| const { items, open } = props | ||
| return !!(items && items.length && open) |
There was a problem hiding this comment.
Consider if it is enough to check the open prop. If so, consider if we can collapse this function to inline logic.
|
|
||
| this.itemRef.current.focus() | ||
| }, | ||
| collapse: e => { |
There was a problem hiding this comment.
We've all agreed splitting the handlers into single purpose functions is correct. let's get this merged in a separate PR. we'll continue to discuss the shouldHandle and other concerns in this PR.
|
Closing as this has seen no activity for awhile. Please reopen if still relevant. Thanks! |
As agreed during the discussion, will keep this PR for further discussion on achieving better solution for having conditional action handler based on an event object.
Meanwhile, a split of action handlers was introduced in another PR #1622
Fixes #1502
PROBLEM
There a lot of confusion in key actions, as initially key action was aimed to do always one thing, now it can do multiple things, plus on different conditions of props values and event object.
Example of such actions:
Dialog -
closeAndFocusTriggerAttachment:
TreeItem:
Also already discussed with @kuzhelov, here is a comment which is totally valid

SOLUTION
I've made some investigation, things that I found out:
For example, we have the next defined actions:
When a user press
SPACE, the sequence of called actions will beWhen a user press
ENTER, the sequence of called actions will beThat means, in cases where we have actions like
closeAndFocusTriggerinDialogkeyActionscan be transformed FROM:TO:
And then implementation in
Dialog:FROM:
TO:
Also, for cases when we depend on conditions like checking values of props and state, event object, we can extend API of
keyActionsand allow user to specify condition when the specific action should be called.Extended API:
I introduced changes in
TreeItemandtreeItemBehaviorto showcase how it will work.Example of usage of
conditionprop intreeItemBehavior... receiveFocus: { keyCombinations: [{ keyCode: keyboardKey.ArrowLeft }], condition: doesEventComesFromChildItem, }, collapse: { keyCombinations: [{ keyCode: keyboardKey.ArrowLeft }], condition: (event, props: TreeItemBehaviorProps) => !doesEventComesFromChildItem(event, props) && props.open, }, ...And then in
TreeItem:CONCERNS
I hesitate if should we move all conditions to behaviors as they're a part of the inner logic of components. Clients have no idea how they can impact if to change them.
I want us to discuss and agree on these points: