Commit Graph

25 Commits

Author SHA1 Message Date
Mo Sattler b3c0cbef48 Small cleanup in React Readme (#253)
remove unused import in example
2021-04-02 15:55:15 +02:00
Robin Malfait b949b4bbfa add missing imports
Closes: #255

Co-authored-by: Pier-Luc Gendreau <Zertz@users.noreply.github.com>
2021-04-02 15:55:15 +02:00
Alexander Bluhm e53a562d9f Added new examples for switch components (React, Vue) (#245)
* Added new example for switch component (React)

* Added new example for switch component (Vue)
2021-04-02 15:55:15 +02:00
Robin Malfait 648a2843e6 Multiple new components (#220)
* add Disclosure component

* expose the Disclosure component

* add Disclosure example component page

* temporary fix selector because of JSDOM bug

* add useFocusTrap hook

* add FocusTrap component

* expose FocusTrap

* add Dialog component

* add Dialog example component page

* expose Dialog

* random cleanup

* make TypeScript a bit more happy

* add Switch.Description component for React

* add Switch.Description component for Vue

* ensure focus event is triggered on click when element is focusable

* remove Dialog.Button and Dialog.Panel from accessibility assertions

* add Portal component

* expose Portal

* always render Dialog in a Portal

* add useInertOthers hook

This will allow us to mark everything but the current ref as "inert".
This is important for screenreaders, to ensure that screenreaders and
assistive technology can't interact with other content but the current
ref.

This implementation is not ideal yet. It doesn't take into account that
you can use the hook in 2 different components. For now this is fine,
since we only use it in a Dialog and you should also probably only have
a single Dialog open at a time.

Will improve this in the future!

* use the useInertOthers hook

* add scroll lock to the dialog

* ensure we respect autoFocus on form elements within the Dialog

If we have an autoFocus on an input, that input will receive focus. Once
we try to focus the first focusable element in the Dialog this could be
lead to unwanted behaviour. Therefore we check if the focus already is
within the Dialog, if it is, keep it like that.

* only mark aria-modal when Dialog is open

* add initialFocus option to Dialog, FocusTrap & useFocusTrap

* add tests and a few fixes for the initialFocusRef functionality

* forward ref to underlying Dialog component

* close Dialog when it becomes hidden

Could happen when this is in md:hidden for example

* prevent infinite loop

When we `Tab` in a FocusTrap it will try and focus the Next element. If
we are in a state where none of the elements inside the FocusTrap can be
focused, then we keep trying to focus the next one in line. This results
in an infinite loop...

To mitigate this issue, we check if we looped around, if we did, it
means that we tried all the other focusable elements, therefore we can
stop.

* isIntersecting doesn't work in every scenario

When page is scrollable, when dialog is translated of the page. Now just checking for sizes, which should be enough for md:hiden cases

* render Portal contents in a div

Otherwise you can't use multiple Portal components if you render multiple children inside each Portal

* ensure the props bag is typed

* add getByText and assertContainsActiveElement helpers

* add Popover component

* expose Popover

* add Popover example component page

* add quick checks to prevent useless renders

* drop incorrect close function

* update Changelog

* make test error more readable when comparing DOM nodes

* actually call .focus() on the element

This ensures that the document.activeElement becomes the focused element.

* improve useSyncRefs, because ...refs is *always* different

* add dedicated focus management utilities

* refactor useFocusTrap, use focus management utilities

* fix regression while using outside click

There might be a chance that you didn't even notice this *bug*. The idea
is that when you click outside, that the Menu or Listbox closes. However
there is another step that happens:

1. When you click on a focusable item, keep the focus on that item.
2. When you click on a non-focusable item, move focus back to the
   Menu.Button or Listbox.Button

We broke part 2, we never returned to the Menu.Button or Listbox.Button.
This is (might) be important for screenreaders so that they don't "get lost",
because if you click on a non-focusable item, the document.body becomes
the active element. Confusing.

* add outside-click to Dialog itself

* update docs
2021-04-02 15:55:14 +02:00
Robin Malfait 3171f4f701 add changelog (#232)
* update docs

* add CHANGELOG
2021-02-06 16:24:43 +01:00
Robin Malfait ab820ded09 update React Transition docs (#203) 2021-01-22 18:35:26 +01:00
ellreka 037079af61 docs: rename class to className (#139) 2020-12-16 15:06:28 +01: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 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 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
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
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 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
Bhanu Teja Pachipulusu 412cc950aa docs: fix typo in React README (#22) 2020-09-30 10:25:30 +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
Utkarsh Kukreti 6d6be636d3 docs(React): fix "Transition" link href in @headlessui-react readme (#9) 2020-09-25 10:51:37 +02:00
Nathan Jaremko 20ddb3e639 docs(React): improve documentation for Menu transitions (#7)
* Improve documentation for Menu transitions

* Update README.md
2020-09-25 10:49:56 +02:00
Adam Wathan b051f13d80 docs: Add demo links 2020-09-24 13:41:16 -04:00
Adam Wathan 4b0207ad71 docs: Document React Menu, tweak Transition and Vue docs to be consistent 2020-09-16 15:07:02 -04:00
Robin Malfait 8b546f054b setup @headlessui/react package 2020-09-16 18:20:49 +02:00