Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combobox: input defaultValue change when displayValue change #3044

Closed
olivierpascal opened this issue Mar 20, 2024 · 1 comment · Fixed by #3048
Closed

Combobox: input defaultValue change when displayValue change #3044

olivierpascal opened this issue Mar 20, 2024 · 1 comment · Fixed by #3048
Assignees

Comments

@olivierpascal
Copy link

olivierpascal commented Mar 20, 2024

Problem: as Combobox displayValue change, the input defaultValue also change.

From what I understand, displayValue is an arbitrary value that is used to map a value to a value used for presentation only.
The defaultValue should not change between renders.

What package within Headless UI are you using?
What version of that package are you using?

@headlessui/react@v1.7.18

What browser are you using?

Chrome, Firefox

Reproduction URL

https://codesandbox.io/p/devbox/inspiring-smoke-5w6ccj

This is the Combobox demo. What I've changed:

const CustomInput = forwardRef(function CustomInput(props, ref) {
  console.log('defaultValue:', props.defaultValue);
  return <input ref={ref} {...props} />;
})

// ...

<Combobox.Input
  as={Fragment}
  displayValue={(person) => String(Math.random())}
>
  <CustomInput onChange={(event) => setQuery(event.target.value)} />
</Combobox.Input>

As you type in the input field, the defaultValue is changing to match the random displayValue.

@RobinMalfait
Copy link
Collaborator

Hey!

This should be fixed by #3048, and will be available in the next release.

You can already try it using:

  • npm install @headlessui/react@insiders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants