Skip to content
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

feat: Add keyboard navigation #225

Merged
merged 77 commits into from
May 1, 2019
Merged

feat: Add keyboard navigation #225

merged 77 commits into from
May 1, 2019

Conversation

ellinge
Copy link
Collaborator

@ellinge ellinge commented Mar 27, 2019

Work in progress.

Adds keyboard navigation as an option. Inspired by:
https://www.w3.org/TR/wai-aria-practices-1.1/examples/treeview/treeview-1/treeview-1a.html
https://www.w3.org/TR/wai-aria-practices-1.1/examples/combobox/aria1.1pattern/listbox-combo.html
Also have looked at react-select

Also adds a11y-tests with axe. The only violation identified is missing label for seachInput though.
Added possibility to pass label with id which sets aria-labelledby or else aria-label on searchInput.

Added some related aria-attributes based on examples. Probably more needed though. This is mostly covered to handle traversing of nodes with keyboard and not how we should handle tags and actions by keyboard. This is something to start with at least.

Sample up and running here:
https://ellinge.github.io/react-dropdown-tree-select-test/#DevelopTemp-nocheckeddefault

Turned off can be seen here:
https://ellinge.github.io/react-dropdown-tree-select-test/#DevelopTemp-keyboardnavigationoff

Partly addresses #216

  • New feature

@ellinge ellinge changed the title Feat/#216 feat: Add keyboard navigation Mar 27, 2019
src/utils/keyboardNavigation.js Outdated Show resolved Hide resolved
src/tree-manager/index.js Outdated Show resolved Hide resolved
src/tree-manager/index.js Outdated Show resolved Hide resolved
src/tree-manager/index.js Outdated Show resolved Hide resolved
src/utils/keyboardNavigation.js Outdated Show resolved Hide resolved
src/utils/keyboardNavigation.js Outdated Show resolved Hide resolved
src/tree-manager/index.js Outdated Show resolved Hide resolved
@mrchief mrchief added the wip Work In Progress label Mar 27, 2019
Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 25743 lines exceeds the maximum allowed for the inline comments feature.

@ellinge ellinge closed this Mar 28, 2019
@mrchief mrchief removed the wip Work In Progress label Mar 28, 2019
mrchief and others added 6 commits April 13, 2019 20:51
# Conflicts:
#	.codeclimate.yml
#	.prettierrc
#	src/index.js
#	src/input/index.js
#	src/tag/index.js
#	src/tree-node/index.js
#	src/tree-node/index.test.js
#	src/tree/index.js
#	yarn.lock
@mrchief
Copy link
Collaborator

mrchief commented Apr 22, 2019

@ellinge, help me figure out the merge sequence, please! Ideally, it shouldn't matter, but since we have overlapping PRs, I'm trying to minimize the effort here. What do you say to this order:

  1. 225, followed by
  2. 233 - do a release
  3. 230, followed by
  4. 242 - do a release

@ellinge
Copy link
Collaborator Author

ellinge commented Apr 22, 2019

@mrchief sounds good. Will probably need more tweaking (WCAG) but perhaps it’s better to start off with something than waiting forever for the perfect PR. Haven’t really had the time or energy to do any more tries with actions and the tag-navigation.

The good thing is that even if we need to change something with aria or keyboard no one should really rely on them (css selectors or from outside in code I mean).

@mrchief
Copy link
Collaborator

mrchief commented Apr 22, 2019

@mrchief sounds good. Will probably need more tweaking (WCAG) but perhaps it’s better to start off with something than waiting forever for the perfect PR. Haven’t really had the time or energy to do any more tries with actions and the tag-navigation.

The good thing is that even if we need to change something with aria or keyboard no one should really rely on them (css selectors or from outside in code I mean).

Yep & Yep! So I'm gonna start in that order and try to close the PRs.

Copy link
Collaborator

@mrchief mrchief left a comment

Choose a reason for hiding this comment

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

Left a few comments. In the interest of time, we can get this merged and have those addressed as future improvements if fixing them takes longer than a few minutes. The regex one, in particular, should be looked upon as once we release it as such, it sort of creates an expectation and would be harder to pull back in future releases.

if (!showDropdown && (keyboardNavigation.isValidKey(e.key, false) || /^\w$/i.test(e.key))) {
// Triggers open of dropdown and retriggers event
e.persist()
this.handleClick(null, () => this.onKeyboardKeyDown(e))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Help me understand why we're doing it this way - especially why we're calling onKeyboardKeyDown again within the onKeyboardKeyDown handler.

I believe you're trying to reuse the state setting logic and then react after that logic does its thing? If so, I think it's time to refactor handleClick.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wait for the state to update and retrigger the event to select the first node in the now visible dropdown.

src/index.js Show resolved Hide resolved
src/index.keyboardNav.test.js Show resolved Hide resolved
src/index.js Show resolved Hide resolved
src/index.js Show resolved Hide resolved
src/index.js Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Apr 24, 2019

Code Climate has analyzed commit 5edbc88 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@mrchief mrchief merged commit 96ff9c9 into dowjones:develop May 1, 2019
mrchief pushed a commit that referenced this pull request May 3, 2019
* feat: Test try a11y in test with axe

* fix: Initial commit (non working)

* fix: Working keyboard navigation

* fix: Backspace only on empty search

* fix: Adjust code to check codeclimate

* fix: Refactored some parts to utils

* fix: Refactored some parts to utils

* fix: Code refactoring

* fix: Add documentation

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Add to typings

* fix: Close on Enter

* fix: Refactor

* fix: Added test

* fix: Added some aria

* fix: Add label option

* fix: Render until node on pagedown

* fix: More tests added and fix pagedown on large search result

* fix: Modify output on violations

* fix: Code smells

* fix: Updated doc and center scrollIntoView, fix hasMore()

* fix: Trigger on*-events properly, only open for chars and whitelist

* fix: Skip som aria in this branch

* fix: Add tests and fix snapshot

* fix: Add tests and fix snapshot

* fix: Enabled by default

* fix: Avoid scroll of whole page, only dropdown

* fix: Remember focus during prop updates

* fix: Delete unintentional dist-file

* fix: Do not select readOnly/disabled

* fix: Switch to babel-plugin-transform-runtime instead

* fix: Add label to trigger as well

* fix: Highlight tag on focus, ad aria-labels

* fix: Highlight tag on focus, ad aria-labels

* fix: Update snapshots, match default

* fix: Allow navigate to disabled/readonly

* fix: Code review/smells fixes

* fix: Code smell

* fix: Code smell

* fix: Move to a11y-folder, shared onKeyDown test method

* fix: Build error and tabIndex

* fix: Set new focus after delete

* fix: Code climate

* fix: Code climate

* fix: Select on tab for simpleSelect

* fix: Add more tests

* fix: Add prop for setting remove aria-label

* fix: Code climate

* fix: Add typing for labelRemove

* fix: Adjust timeout

* style: Bring prettier manually to reduce conflicts

* fix: Prettier and removed comment

* fix: Added migration guide

* fix: Bundle text props

* fix: Typing errors

* fix: Renamed prop

* Revert "fix: Renamed prop"

This reverts commit 4145f8c.

* Revert "fix: Typing errors"

This reverts commit 6aa4beb.

* Revert "fix: Bundle text props"

This reverts commit 4256ce2.

* Revert "fix: Added migration guide"

This reverts commit a4fc033.

* fix: Validate radioSelect also

* fix: Moved around methods

* refactor: Separate out test utils from exported ones

* refactor: Use ES6 getter instead of custom method for accessing tags
@mrchief
Copy link
Collaborator

mrchief commented May 4, 2019

Looks like babel-runtime is getting bundled which caused the bundle size to jump to 19KB

image

I'm checking if we can get rid of it.

@ellinge ellinge deleted the feat/#216 branch May 6, 2019 07:18
@mrchief
Copy link
Collaborator

mrchief commented Jun 10, 2019

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants