Commit Graph

68 Commits

Author SHA1 Message Date
Robin Malfait ab820ded09 update React Transition docs (#203) 2021-01-22 18:35:26 +01:00
Robin Malfait 5fb605205d apply disabled fix when inside a disabled fieldset (#202)
And if we are in a disabled fieldset, double check that we are not in
the first legend. Because in that case we are visually outside of the
fieldset and according to the spec those elements should **not** be
considered disabled.

Fixes: #194
2021-01-22 15:41:09 +01:00
Robin Malfait 17a853501d ensure Switch has type="button" (#192)
Closes: #178

Co-authored-by: =?UTF-8?q?Oskar=20L=C3=B6fgren?= <islander.abroad@gmail.com>

Co-authored-by: =?UTF-8?q?Oskar=20L=C3=B6fgren?= <islander.abroad@gmail.com>
2021-01-08 23:00:39 +01:00
ellreka 037079af61 docs: rename class to className (#139) 2020-12-16 15:06:28 +01:00
Matthew Hailwood c79aa36c14 Add displayName to all contexts in react (#175) 2020-12-16 15:02:38 +01:00
Robin Malfait 78ebd3eb23 prevent scrolling when refocusing items
Fixes #161
2020-11-30 13:12:41 +01:00
Robin Malfait 96e0fa96bd remove unused d dependency 2020-11-30 12:35:53 +01:00
Robin Malfait 24725216e4 fix: outside click refocus bug (#114)
* add watch script

* make interactions in Vue and React consistent

* re-work focus restoration

When we click outside of the Menu or Listbox, we want to
restore the focus to the Button, *unless* we clicked on/in an element
that is focusable in itself. For example, when the Menu is open and you
click in an input field, the input field should stay focused. We should
also close the Menu itself at this point.

* add examples with multiple elements

* bump dependencies
2020-10-20 15:38:12 +02:00
Robin Malfait 47b3ad1387 chore: Cleanup duplication (#109)
* remove duplicate calculate-active-index calculation

* make codebase a bit more consistent

* remove duplicate resolve-prop-value
2020-10-19 12:21:12 +02:00
Robin Malfait aab23c9077 feat: add render features + render strategy (#106)
* add unmount strategy to README (React)

* add unmount strategy to README (Vue)

* add different render features (React)

* use render features in Menu and Listbox (React)

* add different render features (Vue)

* use render features in Menu and Listbox (Vue)

* bump dependencies

* add ability to change the ref property using `refName`

Example use case:

```tsx
// Some components have this API with an `innerRef`. The suggested approach is to use
// `React.forwardRef` so that you get the actual `ref` value. However if you already have this
// `innerRef` API than we can use the `refName="innerRef"` to give the `ref` prop a good name. It
// defaults to `ref` so that it still works everywhere else.

function MyButton({ innerRef, ...props }) {
  return <button ref={innerRef} {...props} />
}

<Menu.Button as={MyButton} refName="innerRef" />
```

* small cleanup, move refs to props we control

* add tests for the render abstraction (Render)

+ use the unique __ symbol as a default value in the Props type for the
  omitable props.

* use render features in Transition (React)

* add/update Transition examples to also showcase the `unmount={false}` render strategy

* bump dependencies

* add example with nested unmount/hide transitions

* add unmount to Transition documentation
2020-10-18 15:34:05 +02:00
Robin Malfait 7d4af1ad3a chore: bump dependencies (#100) 2020-10-14 12:51:10 +02:00
Robin Malfait 53776af89e docs: improve documentation (#91)
* format README's with Prettier

* hoist people list

otherwise the reference will never be the same when you select a new item. Alternative could be to put it in a ref or useMemo or something.

* make whitespace consistent
2020-10-12 13:58:54 +02:00
Robin Malfait 5bb7df9d93 chore: bump dependencies (#90) 2020-10-12 12:27:11 +02:00
Robin Malfait deee4dfa20 bump dependencies 2020-10-08 15:33:47 +02:00
Robin Malfait a5089d07b1 feat: Add Transition events (#57)
* fix wrong class in tests

* add Transition event callbacks

* add Transition Modal example with Event callbacks

* update props table of Transition component
2020-10-08 15:30:10 +02:00
Robin Malfait 7701a48c64 fix Listbox.Option value typing 2020-10-08 15:15:30 +02:00
Tobias Reich c33fc2568f docs: fix variable name in README (#71)
Looks like an old variable that hasn't been renamed
2020-10-07 11:43:47 +02:00
Robin Malfait c7b91dc731 fix: allow disabling the Menu/Listbox button (#56)
* make sure the Menu.Button can be disabled (React)

* make sure the MenuButton can be disabled (Vue)

* make sure the Listbox.Button can be disabled (React)

* make sure the ListboxButton can be disabled (Vue)
2020-10-06 14:41:54 +02:00
Robin Malfait fecd61dff6 ensure that you can't use Enter to invoke the Switch
And a bunch of keyPress and keyboard related shenanigans
2020-10-06 14:00:01 +02:00
Robin Malfait 6ea5c93457 chore: bump dependencies 2020-10-06 11:01:46 +02:00
Manaia Junior 738ae3a9dd docs: Update table of contents and fix code snippet of Listbox (#50) 2020-10-05 22:49:16 -04:00
Adam Wathan b07a298188 v0.2.0 2020-10-05 21:50:45 -04:00
Adam Wathan b761bd3203 docs: Update table of contents and other navigation 2020-10-05 21:45:24 -04:00
Adam Wathan d0720c27c5 docs: Add switch documentation 2020-10-05 21:41:26 -04:00
Adam Wathan a1fcf52443 docs: Fix mistake in docs 2020-10-05 15:44:16 -04:00
Adam Wathan a157039c37 docs: Update Listbox documentation for React and a bit of Vue 2020-10-05 15:30:18 -04:00
Adam Wathan 6ec1fa8bd3 docs: Update Codesandbox links for Listbox components 2020-10-05 14:40:30 -04:00
Robin Malfait 734830ea7b Listbox documentation (#28)
* run prettier on README

* add Listbox documentation
2020-10-05 14:35:25 -04:00
Robin Malfait fc42ddedcf ensure options in listbox can be objects 2020-10-05 20:05:53 +02:00
Robin Malfait 7d402c4213 fix: button focus management (#47)
* make sure the Button is focused when the Menu closes (React)

* make sure the Button is focused when the Menu closes (Vue)

* make sure the Button is focused when the Listbox closes (React)

* make sure the Button is focused when the Listbox closes (Vue)
2020-10-05 18:09:10 +02:00
Robin Malfait 6e3d496998 feat: add Switch component (#26)
* add Switch component

* add tests to verify that we can click the label to toggle the Switch

* use onKeyUp to prevent triggering the onClick in firefox
2020-10-05 16:47:31 +02:00
Robin Malfait fa6e5a354e fix: cleanup transition component (#45)
Fixes: #25
2020-10-05 16:43:55 +02:00
dependabot[bot] 7c46f27674 chore: Bump framer-motion from 2.7.6 to 2.7.7 (#42)
Bumps [framer-motion](https://github.com/framer/motion) from 2.7.6 to 2.7.7.
- [Release notes](https://github.com/framer/motion/releases)
- [Changelog](https://github.com/framer/motion/blob/main/CHANGELOG.md)
- [Commits](https://github.com/framer/motion/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-05 14:13:30 +02:00
dependabot[bot] a5a3ae8bc1 chore: Bump @types/react from 16.9.49 to 16.9.50 (#43)
Bumps [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) from 16.9.49 to 16.9.50.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-05 14:09:35 +02:00
Arno Schutijzer ef25b08cb2 docs: fix typo (#29) 2020-10-02 22:59:07 +02:00
Robin Malfait 99ecdaefd4 update branding
Replace Tailwind UI with Headless UI
2020-10-02 13:56:47 +02:00
Robin Malfait 58ff88698b feat: add Listbox component (#3)
* make jest monorepo aware

* add @testing-library/jest-dom for custom matchers

This way we can use expect(element).toHaveAttribute(key, value?)

* abstract keys enum

* change type to unknown, because we don't know the return value

* update use-id hook, make it suspense aware

Thanks Reach UI!

* hoist the disposables collection

* add accessbility assertions for listbox

Also made it consistent for the Menu component and simplified some of the assertions

* add use-computed hook

This allows us re-render when hooks change, but also return a value. So this is a combination of useEffect and a useState value.

* add Listbox component

* bump dependencies

* add listbox example

* add lint-staged

This way we will only lint the files that have been staged and ready to be committed instead of the whole codebase

* add missing prevent defaults

* improve tests to verify that we can actually update the value of the listbox

* scroll the active listbox item into view

* small optimization, only focus "Nothing" on pointer leave when we are the active item

We used to always go to "Nothing" on pointer leave. And while this code
doesn't get called often, it *gets* called if you are using your arrow
keys and the mouse pointer is still over the list.

* bump dependencies

Also moved the tailwind dependencies to the root

* fix typo

* drop the default Transition inside the Menu and Listbox components

* update examples to reflect drop of default Transition wrapper

* rename Listbox.{Items,Item} to Listbox.{Options,Option}

Also rename all instances of `item` to `option` in tests and comments
and what have you...

* fix typo

* drop disabled prop, use aria-disabled only
2020-10-02 11:05:41 +02:00
Bhanu Teja Pachipulusu 412cc950aa docs: fix typo in React README (#22) 2020-09-30 10:25:30 +02:00
Robin Malfait 7877632299 mark fallthrough as expected 2020-09-29 15:52:54 +02:00
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 878e417139 version 0.1.3 2020-09-29 00:01:50 +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 93f315b066 add prepublishOnly hooks 2020-09-25 16:11: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
Juan Luis Rojas León 46a33b2fbd docs(React): jsx wrapped in enclosing tags (@headlessui-react/readme.md) (#10) 2020-09-25 10:54:16 +02:00