-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Controlled ComboBox
's onSelectionChange
is fired when blurring the input
#7698
Comments
hitting the same issue. This only happens if |
seems it's not so simple. You can:
the key selection hasn't changed but you would expect the input value to be restored as is done in this example. For an uncontrolled selection this happens automatically, but for the controlled it happens inside tldr |
Thanks for looking into that, yes, according to the docs for fully controlled, the onSelectionChange is needed in order to reset the input value. I'll close as working as intended. |
Hmm, not sure I'm tracking with why this would be intended. It seems like the primary (only?) use case for this behavior is if you have a ListItem active via Up/Down arrows and tab away from the ComboBox input. In that case, yes we want to select the active item on blur so an I don't see how this is intuitive in any other situation, as blurring the input only makes a selection in that scenario. In terms of resetting the input value on blur, well, there is an |
IMO it's not intuitive at all. I didn't expect
yeah, indeed it sounds as if |
Yeah, our current Combobox state hook implementation is pretty complex and we are hoping to refactor it in the future now that we've added Autocomplete support to RAC. We could possibly handle resetting the input value on blur, but then we'd need to do the following:
This would be a breaking change unfortunately, and may still have unforeseen issues. Alternatively, we could look to just not fire react-spectrum/packages/@react-stately/combobox/src/useComboBoxState.ts Lines 296 to 299 in bcc12ad
react-spectrum/packages/@react-stately/combobox/src/useComboBoxState.ts Lines 344 to 346 in bcc12ad
react-spectrum/packages/@react-stately/combobox/src/useComboBoxState.ts Lines 316 to 319 in bcc12ad
props.onSelectionChange?.(selectedKey); in a check like if (selectedKey) {...
The problem is that this code is also called in cases such as the following flow:
This flow SHOULD trigger |
Again, just to reiterate, the team would love to untangle/refactor some of this interdependent logic in the combobox hooks are waiting till we finalize the Autocomplete hook logic and thus look to refactor ComboBox. I think it absolutely makes sense to not call However, in the scope of the original issue here, is there an issue that the |
Provide a general summary of the issue here
Blurring the
ComboBox
input calls theonSelectionChange
handler.🤔 Expected Behavior?
onSelectionChange
should only run when theselectedItem
prop changes.😯 Current Behavior
onSelectionChange
runs on input blur (in addition toonBlur
)💁 Possible Solution
No response
🔦 Context
No response
🖥️ Steps to Reproduce
https://stackblitz.com/edit/vitejs-vite-w6je8woh?file=src%2FApp.tsx
Version
1.6.0
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Mac OS
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: