Skip to content

Commit

Permalink
Fix ListboxOptions being incorrectly marked as inert (#3466)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RobinMalfait authored Sep 9, 2024
1 parent cb86665 commit 07c9f1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Fix `ListboxOptions` being incorrectly marked as `inert` ([#3466](https://github.com/tailwindlabs/headlessui/pull/3466))

## [2.1.5] - 2024-09-04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
? false
: modal && data.listboxState === ListboxStates.Open
useInertOthers(inertOthersEnabled, {
allowed: useEvent(() => [data.buttonElement, data.optionsElement]),
allowed: useCallback(
() => [data.buttonElement, data.optionsElement],
[data.buttonElement, data.optionsElement]
),
})

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

0 comments on commit 07c9f1f

Please sign in to comment.