-
Notifications
You must be signed in to change notification settings - Fork 1k
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 - Typing does not replace existing value #2528
Comments
we are also experiencing this issue and will be looking forward to the solution. |
Hey, thank you for this bug report! 🙏 I think the current solution behaves more as a native input field (where nothing is selected and typing adds characters to the current cursor position) but I can see why you want it to behave differently such that your users don't have to do an additional "select all"-type actions before typing. While the proposed solutions are good, there are also very tricky exceptions that you have to keep in mind and they are typically different depending on the use case you are trying to solve. For example if you are working with countries and I want to change I also think that trying to encode various "strategies" for this behaviour might be a bit too much right now. But I'm open to thinking about this more in the future. But let's try to find a solution for your current problem first, before we try to add new APIs. Now, the last option you mentioned is a very interesting one:
I think this is a clean solution because then you can immediately start typing (and text will be replaced because it is selected), and if you don't want this you can click or use arrow keys and can start typing text without "magically" replacing all text. That said, I also think that while this functionality is very interesting, this shouldn't be the default behaviour that we expose. Main reasoning behind this is that a native The good news is that Headless UI forwards all props to the underlying components and you should be able to implement this behaviour yourself. This implementation can look like this: - <Combobox.Input />
+ <Combobox.Input onFocus={e => e.target.select()} /> In this implementation we will select the text whenever the Will this solution work for you? Going to close this issue for now, but feel free to discuss further and I will re-open the issue if this doesn't solve your issue! |
@RobinMalfait thanks for the response and the suggestion. I respect the decision to minimize non-native input features. Your The only thing that may be worth considering is the fact that after you make a selection, the next time you open the combobox, the cursor jumps to the beginning of the input. This part is what seems most like a bug to me. Assuming that's not intentional, I'm happy to help explore the code at some point to see why that might be happening. |
Yep you are right, that part where the cursor jumps to the front is the strange part. Will investigate! |
@djflorio I've made a PR that makes the position of the caret consistent (at the end) when you select a new option. We will also skip that behaviour if you made a custom selection. For example when you used This should be fixed by #2568, and will be available in the next release. You can already try it using:
|
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.7.14
What browser are you using?
Chrome
Reproduction URL
As of when this issue was created, it could be reproduced in the demo within the Combobox docs:
https://headlessui.com/react/combobox
Describe your issue
Currently, when you open the Combobox when a value is populated, the cursor appears after the current value's text. If you start typing, it appends the text to the current value.
If you select a new option, and then open the Combobox again, the cursor does jump to the beginning of the current value text (as expected). However, as you type, it appends the text to the beginning of the current value text, rather than replacing it.
Both of these scenarios are unintuitive, and require the user to manually clear the current value text before performing a new search.
What I believe should be the behavior:
The text was updated successfully, but these errors were encountered: