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

Expose moveFocus() #282

Merged
merged 5 commits into from Sep 21, 2021
Merged

Expose moveFocus() #282

merged 5 commits into from Sep 21, 2021

Conversation

jaksenko
Copy link
Contributor

@jaksenko jaksenko commented Sep 2, 2021

This makes the library ready for menus that open on hover.

This is a great library that handles keyboard users and accessibility perfectly, but only when your submenu opens on click. In our company the menu must open on hover, which can be achieved simply by attaching mouse events to the element:

<li className={styles.menuItem} onMouseEnter={() => setIsOpen(true)} onMouseLeave={() => setIsOpen(false)}>

But once menu is open, hovering over items won't change focus element. This again can be done by attaching mouse event to submenu item:

onMouseEnter={(elem) => elem.target.focus()}

However, the internal state of this library won't change so once you switch back to keyboard and hit up/down arrow, an unexpected element is focused.

With this change, one can use moveFocus to change also internal state:

onMouseEnter={() => moveFocus(index)} // index from `.map(menuItem, index)`

so switching between keyboard and mouse is seamless.

@WesCossick
Copy link
Member

It looks like a few steps were missed from the contributing guide.

@jaksenko jaksenko force-pushed the patch-1 branch 4 times, most recently from 747ab85 to 25ae89c Compare September 6, 2021 08:09
This makes the library ready for menus that open on hover.

This is a great library that handles keyboard users and accessibility perfectly, but only when your submenu opens on click. In our company the menu must open on hover, which can be achieved simply by attaching mouse events to the element:
```
<li className={styles.menuItem} onMouseEnter={() => setIsOpen(true)} onMouseLeave={() => setIsOpen(false)}>
```
But once menu is open, hovering over items won't change focus element. This again can be done by attaching mouse event to submenu item:
```
onMouseEnter={(elem) => elem.target.focus()}
```
However, the internal state of this library won't change so once you switch back to keyboard and hit up/down arrow, an unexpected element is focused.

With this change, one can use `moveFocus` to change also internal state:
```
onMouseEnter={() => moveFocus(index)} // index from `.map(menuItem, index)`
```
so switching between keyboard and mouse is seamless.
@jaksenko
Copy link
Contributor Author

It looks like a few steps were missed from the contributing guide.

Ah right! I hope I didn't miss anything now.

@codecov
Copy link

codecov bot commented Sep 17, 2021

Codecov Report

Merging #282 (7391f69) into master (2b4325e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #282   +/-   ##
=======================================
  Coverage   90.72%   90.72%           
=======================================
  Files           1        1           
  Lines          97       97           
  Branches       31       31           
=======================================
  Hits           88       88           
  Misses          9        9           
Impacted Files Coverage Δ
src/use-dropdown-menu.ts 90.72% <100.00%> (ø)

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 2b4325e...7391f69. Read the comment docs.

Copy link
Member

@WesCossick WesCossick left a comment

Choose a reason for hiding this comment

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

I've left a handful of comments with suggested changes, most of them have to do with how we'll document the return value differently going forward (#283).

In addition to that, it looks like the "Lint code" job is failing. Here's how to address that: https://github.com/sparksuite/react-accessible-dropdown-menu-hook/blob/master/CONTRIBUTING.md#7-format-the-code.

Finally, it looks like the "Return object" page wasn't updated in the docs, but should be, since this PR introduces a new item in the return object.

website/docs/getting-started/using.md Outdated Show resolved Hide resolved
website/docs/getting-started/using.md Outdated Show resolved Hide resolved
website/docs/design/options.md Outdated Show resolved Hide resolved
src/use-dropdown-menu.ts Outdated Show resolved Hide resolved
src/use-dropdown-menu.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
jaksenko and others added 3 commits September 21, 2021 15:03
Co-authored-by: Wes Cossick <WesCossick@users.noreply.github.com>
@jaksenko
Copy link
Contributor Author

Thank you for your thorough review. Hopefully I didn't forget anything this time.

Copy link
Member

@WesCossick WesCossick left a comment

Choose a reason for hiding this comment

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

LGTM and all the CI checks passed. @corymharper do you have any thoughts on this before I merge it?

@corymharper
Copy link
Member

LGTM and all the CI checks passed. @corymharper do you have any thoughts on this before I merge it?

The implementation is fairly straightforward and I don't see any eye glaring problems with it, probably that the tests for this new function and the verbiage in the documentation could be polished, but that can be done in a separated PR.

@WesCossick WesCossick merged commit 02be492 into sparksuite:master Sep 21, 2021
@jaksenko jaksenko deleted the patch-1 branch September 22, 2021 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants