Skip to content

Commit a2177d8

Browse files
authored
Ensure data-open on ComboboxInput is up to date (#3791)
This PR fixes an issue where the `data-open` state on the `ComboboxInput` wasn't always up to date. You can see this behavior if you use the `immediate` prop, focus into the `ComboboxInput`, then press `Escape` to close the combobox. The `data-open` state would still be present. This was just a silly internal bug where the `useMemo` dependencies were not correctly set up. Simplified the internal `useMemo` hook and made sure all the dependencies are available. Fixes: #3718
1 parent 987bfa3 commit a2177d8

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Fix 'Invalid prop `data-headlessui-state` supplied to `React.Fragment`' warning ([#3788](https://github.com/tailwindlabs/headlessui/pull/3788))
1919
- Ensure `element` in `ref` callback is always connected when rendering in a `Portal` ([#3789](https://github.com/tailwindlabs/headlessui/pull/3789))
2020
- Ensure form state is up to date when using uncontrolled components ([#3790](https://github.com/tailwindlabs/headlessui/pull/3790))
21+
- Ensure `data-open` on `ComboboxInput` is up to date ([#3791](https://github.com/tailwindlabs/headlessui/pull/3791))
2122

2223
## [2.2.7] - 2025-07-30
2324

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,16 +903,12 @@ function InputFn<
903903

904904
let optionsElement = useSlice(machine, (state) => state.optionsElement)
905905

906+
let open = comboboxState === ComboboxState.Open
907+
let invalid = data.invalid
908+
let autofocus = autoFocus
906909
let slot = useMemo(() => {
907-
return {
908-
open: comboboxState === ComboboxState.Open,
909-
disabled,
910-
invalid: data.invalid,
911-
hover,
912-
focus,
913-
autofocus: autoFocus,
914-
} satisfies InputRenderPropArg
915-
}, [data, hover, focus, autoFocus, disabled, data.invalid])
910+
return { open, disabled, invalid, hover, focus, autofocus } satisfies InputRenderPropArg
911+
}, [open, disabled, invalid, hover, focus, autofocus])
916912

917913
let ourProps = mergeProps(
918914
{

0 commit comments

Comments
 (0)