There doesn't seem to be a decent way to run a controlled AutoComplete that also allows custom inputs. I can make either of two behaviours happen: the custom values are registered, but can't be cleared without manually deleting all the text, or the custom values can be cleared, but don't propagate to the controlling form. It seems that whenever the Autocomplete loses focus, it triggers the onSelectionChange handler, and if the inputValue doesn't correspond to a selection, this passes null. Either I block this, forcing it to keep the custom entry and the value can't be properly cleared, or if allowed as normal then it erases the custom value. This is the component I've been trying to build, using react-hook-form, and the NextUI Autocomplete.
Is there are a way to do this that I've overlooked?
The supplied code renders an Autocomplete component that can be embedded in a form. Attempting to commit a custom value with this version will see the custom value overwritten when the focus is blurred. If this event is blocked (by replacing the value with the valueOrCustom variable in the event handler), then the inputValue can only be cleared via backspace/delete.
Expected behavior
I would expect the API to allow these behaviours to combine. There doesn't seem to be a single source of truth regarding when/how/why selection or inputValue events are triggered; it isn't possible to ascertain from within the onSelectionChange trigger whether a null key is intended, or the side effect of accepting a custom value. If intentional, then the contents should be cleared; the side effect is undesirable in the first place, but without any way to determine that the null IS a side effect, it can't safely be blocked.
NextUI Version
2.4.6
Describe the bug
There doesn't seem to be a decent way to run a controlled AutoComplete that also allows custom inputs. I can make either of two behaviours happen: the custom values are registered, but can't be cleared without manually deleting all the text, or the custom values can be cleared, but don't propagate to the controlling form. It seems that whenever the Autocomplete loses focus, it triggers the onSelectionChange handler, and if the inputValue doesn't correspond to a selection, this passes null. Either I block this, forcing it to keep the custom entry and the value can't be properly cleared, or if allowed as normal then it erases the custom value. This is the component I've been trying to build, using react-hook-form, and the NextUI Autocomplete.
Is there are a way to do this that I've overlooked?
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
The supplied code renders an Autocomplete component that can be embedded in a form. Attempting to commit a custom value with this version will see the custom value overwritten when the focus is blurred. If this event is blocked (by replacing the value with the
valueOrCustom
variable in the event handler), then the inputValue can only be cleared via backspace/delete.Expected behavior
I would expect the API to allow these behaviours to combine. There doesn't seem to be a single source of truth regarding when/how/why selection or inputValue events are triggered; it isn't possible to ascertain from within the onSelectionChange trigger whether a null key is intended, or the side effect of accepting a custom value. If intentional, then the contents should be cleared; the side effect is undesirable in the first place, but without any way to determine that the null IS a side effect, it can't safely be blocked.
Screenshots or Videos
https://github.com/user-attachments/assets/e76d6772-98ee-413e-a946-cc11394be97d
https://github.com/user-attachments/assets/3fe973e2-a991-4fe1-a205-525b40a059c8
Operating System Version
Browser
Chrome