Commit Graph

285 Commits

Author SHA1 Message Date
Robin Malfait 336faabcab Ensure that you can close the Combobox initially (#1148)
* ensure that you can close the combobox initially

The issue is that `onInput` fires on every keystroke, and we also
handled `onChange` which is triggered on blur in Vue.

This means that the moment we blur, we also called the `handleChange`
code to re-open the combobox because we want to open the combobox if
something changes when the user starts typing.

To fix this, we will splitup the logic so that it will only open the
combobox on input but not on change.

* update changelog
2022-02-24 14:43:08 +01:00
Robin Malfait 475568bcff Make sure that the input syncs when the combobox closes (#1137)
* make sure that the input syncs when the combobox closes

* update changelog
2022-02-23 11:29:51 +01:00
Robin Malfait 0c213b514d Improve concurrency of GitHub Actions (#1128)
* improve concurrency of GitHub Actions

This will allow you to cancel older running actions for the current PR /
branch. This saves you some resources, but more importantly hopefully
frees up some spots in the queue a bit faster.

Saw this on the Node.js repo: https://github.com/nodejs/node/pull/42017

* empty commit to trigger cancellation of previous commit
2022-02-21 23:37:36 +01:00
Robin Malfait 5deddef40b improve demo mode 2022-02-21 15:37:52 +01:00
Robin Malfait 12ddee8766 add demo mode (__demoMode) (#1126) 2022-02-21 14:16:18 +01:00
Robin Malfait ead5ff851a 1.5.0 2022-02-17 21:51:15 +01:00
Robin Malfait 5fe6679265 update changelog 2022-02-17 21:50:13 +01:00
Robin Malfait bd8e88dd33 Trigger scrollIntoView effect when position changes (#1113)
* trigger scrollIntoView effect when position changes

This is important otherwise it could happen that the current active item
is still the active item even if we inserted X items before the current
one. This will result in the active item being out of the current
viewport. To fix this, we will also make sure to trigger the effect if
the position of the active item changes.

* update changelog
2022-02-17 14:55:13 +01:00
Jordan Pittman fd0575b0a7 Fix off-by-one frame issue causing flicker (#1111)
* Fix active item flicker

* apply `nextFrame` -> `requestAnimationFrame` fix to other components

* update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-02-17 07:43:00 -05:00
Robin Malfait 53af7fa861 Move hold prop to the Combobox Options (#1109)
* move `hold` prop to the `Combobox Options`

* update changelog
2022-02-16 17:18:33 +01:00
Robin Malfait 0bf325dae1 Ensure ComboboxInput syncs correctly (#1106)
* ensure ComboboxInput syncs correctly

* update changelog
2022-02-15 11:25:43 +01:00
Robin Malfait 639d8d2d60 only call onChange if it exists 2022-02-11 17:39:50 +01:00
Robin Malfait 706f42b9d7 Bubble Escape event even if Combobox.Options is not rendered at all (#1104)
* bubble Escape event even if `Combobox.Options` is not rendered at all

If you use `<Combobox.Options static />` it means that you are in
control of rendering and in that case we also bubble the `Escape`
because you are in control of it.

However, if you do something like this:
```js
{filteredList.length > 0 && (
  <Combobox.Options static>
    ...
  </Combobox.Options>
)}
```
Then whenever the `filteredList` is empty, the Combobox.Options are not
rendered at all which means that we can't look at the `static` prop. To
fix this, we also bubble the `Escape` event if we don't have a
`Combobox.Options` at all so that the above example works as expected.

* update changelog
2022-02-11 15:24:30 +01:00
Robin Malfait 4ed344aa87 Combobox improvements (#1101)
* ensure combobox option gets activated on hover (while static)

* rename combobox test file

* remove leftover `horizontal` prop

* remove unnecessary handleLeave calls

These are implemented on the `Combobox.Option` instead of the
`Combobox.Options`. This allows you to have additional visual padding
between `Combobox.Options` and `Combobox.Option` and if you hover over
that area then the option becomes inactive.

If we implement it on the `Combobox.Options` instead then this isn't
_that_ easy to do. We can do it by checking the target and whether or
not it is inside a headlessui-combobox-option. This would only have a
single listener instead of `N` listeners though. Potential improvements!

* implement `hold` in favor of `latestActiveOption`

* update changelog

* Allow Escape to bubble when options is static

You’ve taken control of the open/close state yourself in which case this should be allowed to be handled by other event handlers

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-02-10 14:55:56 +01:00
Robin Malfait dcf2f7508a Ensure typeahead stays on same item if it still matches (#1098)
* ensure typeahead stays on same item if it still matches

Fixes: #1090

* update changelog
2022-02-08 19:54:09 +01:00
Jordan Pittman 554d04b01c Fix Combobox issues (#1099)
* Add combobox to Vue playground

* Update input props

* Wire up input event for changes

This fires changes whenever you type, not just on blur

* Fix playground

* Don't fire input event when pressing escape

The input event is only supposed to fire when the .value of the input changes. Pressing escape doesn't change the value of the input directly so it shouldn't fire.

* Add latest active option render prop

* Add missing active option props to Vue version

* cleanup

* Move test

* Fix error

* Add latest active option to Vue version

* Tweak active option to not re-render

* Remove refocusing on outside mousedown

* Update tests

* Forward refs on combobox to children

* Cleanup code a bit

* Fix lint problems on commit

* Fix typescript issues

* Update changelog
2022-02-08 12:59:39 -05:00
Robin Malfait 6fc28c610f temporarily target es2019 instead of es2020 (#1083)
The Headless UI docs require some bumps in packages because it currently
can't handle es2020 features like `??`. This tempory workaround should
fix this in the mean time.
2022-02-02 18:55:36 +01:00
Robin Malfait 719cac5366 Ignore non-option roles (#1081)
* rename `ComboboxState` to `comboboxState` for consistency

* ensure all elements between `role: listbox` and `role: option` are marked as `role: none`

* add test to demonstrate the `role: none`
2022-02-02 18:04:39 +01:00
Robin Malfait f04d460382 Remove orientation for Combobox (#1080)
* remove orientation in Combobox (React)

* remove orientation in Combobox (Vue)
2022-02-02 15:09:57 +01:00
Robin Malfait b3e7302e45 Merge pull request #1078 from tailwindlabs/improve-build
Improve build files
2022-01-31 17:48:52 +01:00
Robin Malfait 47756e2f5a make vue & react playground pages similar
A bit out of scope for this issue, but bothered me while testing around
🙃
2022-01-31 12:40:19 +01:00
Robin Malfait 6174c47291 convert .js to .cjs 2022-01-31 12:29:27 +01:00
Robin Malfait 39751cda4b update changelog 2022-01-31 12:17:02 +01:00
Robin Malfait c65b87ee68 improve build files
Based on: https://nodejs.org/api/packages.html#conditional-exports
2022-01-31 00:10:06 +01:00
Robin Malfait fbaa1ae9da Merge pull request #1071 from tailwindlabs/develop
Next release
2022-01-28 15:46:25 +01:00
Robin Malfait 947bf7ac8b only build @headlessui/react and @headlessui/vue
This used to also build the individual playground packages but that's
not needed on CI (nor locally). Because Vercel will build them for us.
This will safe us some time on CI, since we can run them in parallel now
and only build the actual libraries.
2022-01-28 13:31:24 +01:00
Robin Malfait bef07b3c50 ensure that a path is passed to lint.sh, otherwise default to the current directory 2022-01-28 13:26:04 +01:00
Robin Malfait 8e0e114153 document all scripts 2022-01-28 12:58:11 +01:00
Robin Malfait 885c3b3b4a move prettier-plugin-tailwindcss to dev dependencies 2022-01-28 12:07:41 +01:00
Jordan Pittman d8424fe311 Update type of omit 2022-01-27 18:40:37 -05:00
Jordan Pittman f48bb4659e Fix circular component types 2022-01-27 18:39:18 -05:00
Jordan Pittman 89fd4b202e Update minimum Vue to 3.2 (#1072)
* Remove vercel json file

* Don't use provide/inject outside of setup

* Upgrade minimum vue version

* Mark vue as an external

* Update lockfile

* WIP move render functions into setup

* WIP

* WIP

* Use setup returning render fns for tests
2022-01-27 13:49:26 -05:00
Robin Malfait fdd2629795 Improve overal codebase, use modern tech like esbuild and TypeScript 4! (#1055)
* use esbuild for React instead of tsdx

* remove tsdx from Vue

* use consistent names

* add jest and prettier

* update scripts

* ignore some folders for prettier

* run lint script instead of tsdx lint

* run prettier en-masse

This has a few changes because of the new prettier version.

* bump typescript to latest version

* make typescript happy

* cleanup playground package.json

* make esbuild a dev dependency

* make scripts consistent

* fix husky hooks

* add dedicated watch script

* add `yarn playground-react` and `yarn react-playground` (alias)

This will make sure to run a watcher for the actual @headlessui/react
package, and start a development server in the playground-react package.

* ignore formatting in the .next folder

* run prettier on playground-react package

* setup playground-vue

Still not 100% working, but getting there!

* add playground aliases in @headlessui/vue and @headlessui/react

This allows you to run `yarn react playground` or `yarn vue playground`
from the root.

* add `clean` script

* move examples folder in playground-vue to root

* ensure new lines for consistency in scripts

* fix typescript issue

* fix typescript issues in playgrounds

* make sure to run prettier on everything it can

* run prettier on all files

* improve error output

If you minify the code, then it could happen that the errors are a bit
obscure. This will hardcode the component name to improve errors.

* add the `prettier-plugin-tailwindcss` plugin, party!

* update changelog
2022-01-27 17:07:38 +01:00
Robin Malfait ea26870480 Add Combobox component (#1047)
* start of combobox

* start with a copy of the Listbox

* WIP

* Add Vue Combobox

* Update Vue version of combobox

* Update tests

* Fix typescript errors in combobox test

* Fix input label

The spec says that the combobox itself is labelled directly by the associated label. The button can however be labelled by the label or itself.

* Add active descendant to combobox/input

* Add listbox role to comobox options

Right now the option list *is* just a listbox. If we were to allow other types in the future this will need to be changable

* Update tests

* move React playground to dedicated package

* add react playground script to root

* ensure we only open/close the combobox when necessary

* ensure export order is correct

* remove leftover pages directory from React package

* Only add aria controls when combobox is open

* add missing next commands

* make typescript happy

* build @headlessui/react before building playground-react

* add empty public folder

This makes vercel happy

* wip

* Add todo

* Update tests

Still more updates to do but some are blocked on implementation

* change default combobox example slightly

* ensure that we sync the input with new state

When the <Combobox value={...} /> changes, then the input should change
as well.

* only sync the value with the input in a single spot

* WIP: object value to string

* WIP

* WIP

* WIP groups

* Add static search filtering to combobox

* Move mouse leave event to combobox

* Fix use in fragments

* Update

* WIP

* make all tests pass for the combobox in React

* remove unnecessary playground item

* remove listbox wip

* only fire change event on inputs

Potentially we also have to do this for all kinds of form inputs. But
this will do for now.

* disable combobox vue tests

* Fix vue typescript errors

* Vue tests WIP

* improve combobox playgrounds a tiny bit

* ensure to lookup the correct value

* make sure that we are using a div instead of a Fragment

* expose `activeItem`

This will be similar to `yourData[activeIndex]`, but in this case the
active option's data. Can probably rename this if necessary!

* Update comments

* Port react tests to Vue

* Vue tests WIP

* WIP

* Rename activeItem to activeOption

* Move display value to input

* Update playgrounds

* Remove static filtering

* Add tests for display value

* WIP Vue Tests

* WIP

* unfocus suite

* Cleanup react accessibility assertions code

* Vue WIP

* Cleanup errors in react interactions test utils

* Update vue implementation

closer :D

* Fix searching

* Update

* Add display value stubs

* Update tests

* move `<Combobox onSearch={} />` to `<Combobox.Input onChange={} />`

* use `useLatestValue` hook

* make `onChange` explicitly required

* remove unused variables

* move `<Combobox @search="" />` to `<ComboboxInput @change="" />`

* use correct event

* use `let` for consistency

* remove unnecessary hidden check

* implement displayValue for Vue

* update playground to reflect changes

* make sure that the activeOptionIndex stays correct

* update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-01-27 16:42:47 +01:00
Robin Malfait cae976a18b Remove playground (#1053)
* remove local testing playgrounds

* bump outdated packages
2022-01-19 16:51:09 +01:00
Robin Malfait 186a4cfcef Improve typeahead search logic (#1051)
* improve typeahead search logic

This ensures that if you have 4 items:
- Alice
- Bob
- Charlie
- Bob

And you search for `b`, then you jump to the first `Bob`, but if yuo
search again for `b` then we used to go to the very first `Bob` because
we always searched from the top. Now we will search from the active item
and onwards. Which means that we will now jump to the second `Bob`.

* update changelog
2022-01-19 13:49:57 +01:00
Robin Malfait 2dd57f1cd3 Improve controlled Tabs behaviour (#1050)
* Append tests for Tab.Group's selectedIndex.

* ensure that we correctly use the incoming selectedIndex

* update changelog

Co-authored-by: Ryoga Kitagawa <ryoga.kitagawa@gmail.com>
2022-01-19 11:13:37 +01:00
Robin Malfait a37197694f Ensure correct order when conditionally rendering Menu.Item, Listbox.Option and RadioGroup.Option (#1045)
* ensure correct order in `Menu.Item`

* Update Vue version of menu component ordering issue

* ensure correct order of `Listbox.Option`s

* add test to verify that RadioGroup.Option order is correct

* ensure correct order of `ListboxOption`s

* cleanup

* add test to verify that `RadioGroupOption` order is correct

* update changelog

* use similar a,z signature compared to other places

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-01-18 16:05:01 +01:00
Robin Malfait 1affad1271 Simplify and improve overall structure (#1044)
* simplify CI and make it consistent with CI of tailwindcss

* add contributing guidelines

* use correct org name

* ensure `yarn lint` is fully passing without warnings

* add subject to change message for `insiders` build
2022-01-17 15:46:18 +01:00
Robin Malfait 0ce63d8f7f Next release (#1039)
* placeholder for next release

* improve consistency of changelog
2022-01-17 14:02:00 +01:00
Robin Malfait 147963424a 1.4.3 2022-01-14 18:44:12 +01:00
Robin Malfait 1b85bc89ea update changelog 2022-01-14 18:42:32 +01:00
Robin Malfait b0d8f5f756 cleanup older changelog items 2022-01-14 18:42:13 +01:00
Robin Malfait 3bc7545169 Next release (#916)
* placeholder for next release

* Ensure portal root exists in the DOM (#950)

* ensure that the portal root is always in the DOM

When using NextJS, it happens that between page transitions the portal
root gets removed form the DOM. We will check the DOM when the `target`
updates, and if it doesn't exist anymore, then we will re-insert it in
the DOM.

* update changelog

* Allow `Tabs` to be controllable (#970)

* feat(react): Allow Tab Component to be controlled

* fix falsy bug

`selectedIndex || defaultIndex` would result in the `defaultIndex` if
`selectedIndex` is set to 0. This means that if you have this code:

```js
<Tab.Group selectedIndex={0} defaultIndex={2} />
```

That you will never be able to see the very first tab, unless you
provided a negative value like `-1`.

`selectedIndex ?? defaultIndex` fixes this, since it purely checkes for
`undefined` and `null`.

* implemented controllable Tabs for Vue

* add dedicated test to ensure changing the defaultIndex has no effect

* update changelog

Co-authored-by: ChiefORZ <seb.schaffernak@gmail.com>

* Fix missing key binding in examples (#1036)

Co-authored-by: superDragon <xkloveme@gmail.com>

* Fix slice => splice typo in Vue Tabs component (#1037)

Co-authored-by: Ryan Gossiaux <ryan.gossiaux@gmail.com>

* update changelog

* Ensure correct DOM node order when performing focus actions (#1038)

* ensure that the order of DOM nodes is correct

When we are performing actions like `focusIn(list, Focus.First)` then we
have to ensrue that we are working with the correct list that is
properly sorted.

It can happen that the list of DOM nodes is out of sync. This can happen
if you have 3 Tabs, hide the second (which triggers an unmount and an
`unregister` of the Tab), then re-add the second item in the middle.
This will re-add the item to the end of the list instead of in the middle.

We can solve this by always sorting items when we are adding / removing
items, but this is a bit more error prone because it is easy to forget.
Instead we will sort it when performing the actual keyboard action.

If we didn't provide a list but an element, then we use a
getFocusableElements(element) function, but this already gives you a
correctly sorted list so we don't need to do that for this list.

* add tests to prove the correct order when performing actions

* cleanup code just for tests

It could still happen that this internal list is not ordered correctly
but that's not really a problem we just have the list to keep track of
things.

For our tests we now use the position from the DOM directly.

* update changelog

Co-authored-by: ChiefORZ <seb.schaffernak@gmail.com>
Co-authored-by: superDragon <xkloveme@gmail.com>
Co-authored-by: Ryan Gossiaux <ryan.gossiaux@gmail.com>
2022-01-14 18:38:14 +01:00
Jonathan Reinink e9e6aded54 Tweak wording in changelog (#917) 2021-11-08 08:21:01 -05:00
Robin Malfait 2f987be5b9 bump to 1.4.2 2021-11-08 11:15:43 +01:00
Robin Malfait 0252c6136e update GitHub action name 2021-11-08 11:14:12 +01:00
Robin Malfait ff60cfaf65 update changelog 2021-11-08 11:13:00 +01:00
Robin Malfait b67729e7f6 Merge pull request #826 from tailwindlabs/develop
Next release
2021-11-08 11:10:27 +01:00
Robin Malfait 39b164647f Fix type on Tabs component Vue (#912)
* add `tabs` example to Vue

* use useResolveButtonType for Tabs

* update changelog
2021-11-05 12:57:41 +01:00