Skip to content

Commit 02b43d0

Browse files
authored
Cleanup process in Combobox component when using virtualization (#3495)
This PR is a different approach compared to #3487. Instead of checking whether we are in a test environment (specifically in a Jest environment), I think we can just get rid of the check entirely and use the virtualizer in all environments. This will remove an unnecessary check for `process` being available and gets rid of `process` entirely. It also fixes an issue that #3487 tries to solve where `process` is available, but `process.env` is not. Closes: #3487
1 parent 63daa86 commit 02b43d0

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

packages/@headlessui-react/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Ensure `Element` is available before polyfilling to prevent crashes in non-browser environments ([#3493](https://github.com/tailwindlabs/headlessui/pull/3493))
1313
- Fix crash when using `instanceof HTMLElement` in some environments ([#3494](https://github.com/tailwindlabs/headlessui/pull/3494))
14+
- Cleanup `process` in Combobox component when using virtualization ([#3495](https://github.com/tailwindlabs/headlessui/pull/3495))
1415

1516
## [2.1.8] - 2024-09-12
1617

packages/@headlessui-react/src/components/combobox/combobox.tsx

+7-14
Original file line numberDiff line numberDiff line change
@@ -532,21 +532,14 @@ function VirtualProvider(props: {
532532
return
533533
}
534534

535-
// Scroll to the active index
536-
{
537-
// Ignore this when we are in a test environment
538-
if (typeof process !== 'undefined' && process.env.JEST_WORKER_ID !== undefined) {
539-
return
540-
}
541-
542-
// Do not scroll when the mouse/pointer is being used
543-
if (data.activationTrigger === ActivationTrigger.Pointer) {
544-
return
545-
}
535+
// Do not scroll when the mouse/pointer is being used
536+
if (data.activationTrigger === ActivationTrigger.Pointer) {
537+
return
538+
}
546539

547-
if (data.activeOptionIndex !== null && options.length > data.activeOptionIndex) {
548-
virtualizer.scrollToIndex(data.activeOptionIndex)
549-
}
540+
// Scroll to the active index
541+
if (data.activeOptionIndex !== null && options.length > data.activeOptionIndex) {
542+
virtualizer.scrollToIndex(data.activeOptionIndex)
550543
}
551544
}}
552545
>

packages/@headlessui-vue/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
- Cancel outside click behavior on touch devices when scrolling ([#3266](https://github.com/tailwindlabs/headlessui/pull/3266))
1818
- Fix restoring focus to correct element when closing `Dialog` component ([#3365](https://github.com/tailwindlabs/headlessui/pull/3365))
19+
- Cleanup `process` in Combobox component when using virtualization ([#3495](https://github.com/tailwindlabs/headlessui/pull/3495))
1920

2021
## [1.7.22] - 2024-05-08
2122

packages/@headlessui-vue/src/components/combobox/combobox.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,17 @@ let VirtualProvider = defineComponent({
190190
return
191191
}
192192

193-
// Scroll to the active index
194-
{
195-
// Ignore this when we are in a test environment
196-
if (typeof process !== 'undefined' && process.env.JEST_WORKER_ID !== undefined) {
197-
return
198-
}
199-
200-
// Do not scroll when the mouse/pointer is being used
201-
if (api.activationTrigger.value === ActivationTrigger.Pointer) {
202-
return
203-
}
193+
// Do not scroll when the mouse/pointer is being used
194+
if (api.activationTrigger.value === ActivationTrigger.Pointer) {
195+
return
196+
}
204197

205-
if (
206-
api.activeOptionIndex.value !== null &&
207-
api.virtual.value!.options.length > api.activeOptionIndex.value
208-
) {
209-
virtualizer.value.scrollToIndex(api.activeOptionIndex.value)
210-
}
198+
// Scroll to the active index
199+
if (
200+
api.activeOptionIndex.value !== null &&
201+
api.virtual.value!.options.length > api.activeOptionIndex.value
202+
) {
203+
virtualizer.value.scrollToIndex(api.activeOptionIndex.value)
211204
}
212205
},
213206
},

0 commit comments

Comments
 (0)