Skip to content

Commit 07c9f1f

Browse files
authored
Fix ListboxOptions being incorrectly marked as inert (#3466)
This PR fixes an issue where the `ListboxOptions` component was incorrectly marked as `inert`. We only mark the other elements on the page as `inert` once the `Listbox` is in a visible state. The issue is that the `data.optionsElement` (a reference to the DOM node) was not populated with the actual DOM node yet at the time the `useInertOthers(…)` hook was applied. Due to the usage of `useEvent(…)`, instead of `useCallback(…)` the internal `useEffect(…)` hook didn't re-run because the `allowed` function was already stable. With this fix, the `allowed` function will change whenever its dependencies change. Fixes: #3464
1 parent cb86665 commit 07c9f1f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Fix `ListboxOptions` being incorrectly marked as `inert` ([#3466](https://github.com/tailwindlabs/headlessui/pull/3466))
1113

1214
## [2.1.5] - 2024-09-04
1315

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,10 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
972972
? false
973973
: modal && data.listboxState === ListboxStates.Open
974974
useInertOthers(inertOthersEnabled, {
975-
allowed: useEvent(() => [data.buttonElement, data.optionsElement]),
975+
allowed: useCallback(
976+
() => [data.buttonElement, data.optionsElement],
977+
[data.buttonElement, data.optionsElement]
978+
),
976979
})
977980

978981
// We keep track whether the button moved or not, we only check this when the menu state becomes

0 commit comments

Comments
 (0)