Commit Graph

83 Commits

Author SHA1 Message Date
Robin Malfait 71730fea12 bump version 2021-02-11 19:39:44 +01:00
Robin Malfait bb68793f08 correctly handle TypeScript render abstractions 2021-02-11 19:19:12 +01:00
Robin Malfait d557d50139 ensure correct path to types 2021-02-07 12:08:53 +01:00
Robin Malfait 43effbbe29 v0.3.0 2021-02-06 16:30:08 +01:00
Robin Malfait 3171f4f701 add changelog (#232)
* update docs

* add CHANGELOG
2021-02-06 16:24:43 +01:00
Robin Malfait e9c92924cf Add disabled to listbox (#229)
* allow to press on an element without focusing it first

* add disabled option to the Listbox component
2021-02-06 00:09:13 +01:00
Robin Malfait 9e0df9ee39 ensure valid Menu accessibility tree (#228) 2021-02-05 21:01:28 +01:00
Robin Malfait 9891fa31b9 add better implementation to detect the FPS 2021-02-05 18:15:51 +01:00
Robin Malfait 9e05bbe8d8 ensure the active MenuItem is scrolled into view
Fixes: #227
2021-02-05 18:15:07 +01:00
Robin Malfait ef00732685 cleanup and consistency (#213)
- Made the use of `const` and `let` consistent
- import required functions and types from 'react' instead of using the
  `React.` namespace.
- Added `Expand` type, which can expand complex types to their "final"
  result.
- Ensured that we use `as const` for DEFAULT_XXX_TAG where we used a
  string. So that we have the type of `div` instead of `string` for
  example.
- Used `interface` over `type` where possible. I'm personally more of a
  `type` fan. But the TypeScript recommends `interfaces` where possible
  because they are faster, yield better error messages and so on.
2021-01-30 14:46:54 +01:00
Robin Malfait da179ca72b trigger "outside click" behaviour on mousedown (#212)
Fixes: #95
2021-01-29 21:47:56 +01:00
Robin Malfait 80402e70e1 Fix various event bugs (#211)
* add right click option to the interactions

* add tests to ensure right click behaves as expected

Fixes: #142
Fixes: #167

* fallback to mouse events if pointer events are not supported

When the pointer events are not supported, then this is essentially a
no-op. When they *are* supported, then both the pointer *and* mouse
events will fire.
To mitigate potential issues, we make sure that state changes (and
potential re-renders) are idempotent (we bail out on potential state
updates when we are already ina certain state).

Fixes: #173
Fixes: #167
2021-01-29 20:43:40 +01:00
Robin Malfait 9b0d9e136a bump dependencies (#177)
* bump root dependencies

* bump react related dependencies

* update browserslist db

* remove obsolete shared dependency
2021-01-29 15:14:59 +01:00
Robin Malfait 4459689beb handle keyboard interactions in a more robust way
Browsers. Are. Crazy.

In JSDOM, when you fire an event, you only get that specific event. You
don't get all the magic that the browser gives you. For example, when
you are focused on a button and press to "Tab" then in JSDOM you would
only get a keydown event. However in the browser you get this chain of
events:

1. `keydown` on the current element
2. `blur` on the current element
3. `focus` on the new element
4. `keyup` on the new element

I implemented this "magic", for the `Tab`, `Enter` and `Space` key for
now. Those are the most important currently. `Enter` and `Space` also
trigger `click` events for example.

I also have a "generic" implementation, where a normal press results in:

1. `keydown`
2. `keypress` (in case it has a `charCode` and is "printable", so `alt`
   is ignored)
3. `keyup`

I also ensured that the cancelation when you use an
`event.preventDefault()` happens correctly.

Here is a fun summary: https://twitter.com/malfaitrobin/status/1354472678128820234

Press "Enter" on a button
  -> keydown, keypress, click, keyup

Press "Space" on a button
  -> keydown, keypress, keyup, click

Press "Enter" or "Space" on a button, with event.preventDefault() in the keydown listener
  -> keydown, keyup

Press "Enter" on a button, with event.preventDefault() in the keypress listener
  -> keydown, keypress, keyup

Press "Space" on a button, with event.preventDefault() in the keypress listener
  -> keydown, keypress, keyup, click
2021-01-29 12:23:14 +01:00
Robin Malfait b6212b9d44 ensure that we regenerate the id when it is still null 2021-01-29 12:23:10 +01:00
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