Robin Malfait 17b2d34fe6 Improve performance of Combobox component (#2574)
* add countries data and combobox example

* directly push to the options array

No need to spread here because this will slow things down tremendously.
If you add 5 options, then this will happen:

```js
let options = []
options = [...options, 1]
options = [...options, 2]
options = [...options, 3]
options = [...options, 4]
options = [...options, 5]
```

It's making a lot of copies and has to spread everything it just copied
again. Instead, let's just push to the array:

```js
let options = []
options.push(1)
options.push(2)
options.push(3)
options.push(4)
options.push(5)
```

* only sort options by DOM node once

When registering 50 options, we will re-sort the options based on the DOM
node position for every option that gets registered. This is overkill
and unnecessary. The re-sorting is useful if an option is injected
between 2 options. When we sort the full list for _every_ `registerOption`
call then the result after the last `registerOption` will be the same if
we only sorted after the last `registerOption` call only.

This will ensure that we are skipping a ton of work and only do the work
once at the end where it matters.

* debounce the `goToOption` call until the next frame

This will allow us to perform the task of `goToOption` once instead of
`n` times if they happen really fast after eachother.

This can happen when you are leaving option B and going to option A.
Then the following steps happen:

- Leaving Option B `goToOption(Nothing)`
- Entering Option A `goToOption(A)`

Both will re-render everything because the internal active option index
would be changed. But only the last `goToOption(A)` is the interesting
version here.

We could also move the `goToOption(Nothing)` to the `ComboboxOptions`
(wrapper) itself instead of adding these listeners on each individual
`ComboboxOption`. However, if you add an additional visual piece of DOM
above or between the options, hovering that would not leave the
`ComboboxOptions` and therefore the last `ComboboxOption` would still be
active which we don't want.

* update changelog
2023-07-05 11:10:19 +02:00
2023-06-28 12:23:13 +02:00
2020-09-16 18:19:33 +02:00
2023-04-22 14:43:38 +02:00
2022-01-31 12:29:27 +01:00
2020-09-16 18:19:33 +02:00
2023-01-01 06:25:25 -05:00

Headless UI

A set of completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.


Documentation

For full documentation, visit headlessui.com.

Installing the latest version

You can install the latest version by using:

  • npm install @headlessui/react@latest
  • npm install @headlessui/vue@latest

Installing the insiders version

You can install the insiders version (which points to whatever the latest commit on the main branch is) by using:

  • npm install @headlessui/react@insiders
  • npm install @headlessui/vue@insiders

Note: The insiders build doesn't follow semver and therefore doesn't guarantee that the APIs will be the same once they are released.

Packages

Name Version Downloads
@headlessui/react npm version npm downloads
@headlessui/vue npm version npm downloads
@headlessui/tailwindcss npm version npm downloads

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discuss Headless UI on GitHub

For casual chit-chat with others using the library:

Join the Tailwind CSS Discord Server

Contributing

If you're interested in contributing to Headless UI, please read our contributing docs before submitting a pull request.

S
Description
Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
Readme 6.5 MiB
Languages
TypeScript 95.3%
Vue 4.3%
JavaScript 0.3%
Shell 0.1%