Commit Graph

14 Commits

Author SHA1 Message Date
Robin Malfait 279b021a2b implement type ahead mode on Menu
This will allow us to do 2 things:

- When we are in "type ahead" mode, aka search, we can use spaces to
  search. E.g.: "Account Settings" (notice the space)
- When we are not in "type ahead" mode, we can use `Space` to invoke the
  menu item. We used to only allow `Enter` and `Click`.
2020-09-29 15:34:17 +02:00
Robin Malfait 57ad598202 be consistent with pointer/mouse events 2020-09-29 13:55:19 +02:00
Robin Malfait 4b2aacfdf2 simplify the click / pointer up handling on Menu Item
Thank you @MartinMa for pointing this complexity out!
2020-09-29 12:54:42 +02:00
Robin Malfait fedfc0cc1b ensure to prevent the default behaviour of keyboard navigation 2020-09-28 23:47:50 +02:00
Robin Malfait 93e8b8f4ba fix: outside click behaviour (#19)
* add failing tests to prove the outside-click issue

* fix outside click when we have multiple menu's

- We removed the `toggleMenu` since we only used it in a single spot,
  and had to do some side effect logic (focus & event.preventDefault).
  Wanted to make this consistent between React and Vue.
- If, in the "outside click" logic we detect that we clicked on the
  button, we also ignore it.
- If, we click on the button we will toggle the menu.

Fixes: #18
2020-09-28 15:52:00 +02:00
Robin Malfait e9fd05e06d ensure that anchor links are still clickable
This is an issue in the Vue version (it just works in the React version)
but I added tests for them anyway.

While this solution "works" I am not 100% happy with it. Let me explain
what's happening here and why I am not that happy about it:

- For starters, the Vue `nextTick` is apparently too fast. So what we do
  is when we get the pointer up event, we will close the menu and
  re-focus the button. We ran this code in a `nextTick` so that we can
  ensure that we close the menu *after* all the click events are
  finished. However because this is too fast, the menu is already closed
  and the anchor link is already unmounted and thus not clickable
  anymore. So instead we use a double requestAnimationFrame (to mimick a
  `nextFrame` as seen in the `disposables` from the React code). This
  works, but a bit messy, oh well.
- The next reason why I am not that happy is because I can't reproduce
  it in JSDOM (Jest tests). When you *click* a link in JSDOM it doesn't
  update the `window.location.hash` or `window.location.href`. To mimick
  that behaviour I put a `@click` event on the anchor to verify that we
  actually clicked it. However this already works, even before the
  "fix". So I left a TODO in there so that we can hopefully fix the
  test, so that we _can_ reproduce this behaviour.

Fixes: #14
2020-09-28 12:30:52 +02:00
Robin Malfait 3709ed5b77 only passthrough the aria-disabled prop when true
Drop the disabled prop itself because doesn't make much sense
2020-09-25 16:10:47 +02:00
Robin Malfait 2747745891 ensure that you can not click disabled items 2020-09-25 16:09:40 +02:00
Robin Malfait 93508e97a3 remove test code, use mocks instead 2020-09-18 14:05:22 +02:00
Robin Malfait 1b896b4992 add some dead code elimination markers 2020-09-17 23:24:40 +02:00
Robin Malfait 5f377b946e use headlessui identifier instead of tailwindui 2020-09-17 16:00:50 +02:00
Robin Malfait 59870594c1 inline defaultState
Otherwise we will be mutating the refs, and items from the first Menu on the page
2020-09-17 15:58:37 +02:00
Robin Malfait 76c24680c5 make render logic consistent with the Vue implementation 2020-09-16 23:44:38 +02:00
Robin Malfait 8b546f054b setup @headlessui/react package 2020-09-16 18:20:49 +02:00