ComboBox custom input onChange handler
Environment Information
- Package version(s): 7.145.0
- Browser and OS versions: Edge (chromium) on Linux ubuntu 18.04
Please provide a reproduction of the bug in a codepen: https://codepen.io/verhext/pen/jOrKOPe
Actual behavior:
I not been able to insert my own text, after insert and press enter the text disappears. The option selection works without problems. This appears only when I implement the onChange handler.
Expected behavior:
Actually I expect a result like in microft teams (combobox calendar -> time) or the time settings in outlook online. But I couldn't find a working solution to save user defined entries and dropdowns.
@VerHext Thanks for submitting this issue.
First thank you for providing a codepen that is super helpful for us to iterate on. Could you provide a little more detail on what your expected outcome to be when you provide your own onChange handler? Sounds like you can provide a handler right?
@behowell Please coordinate once we get a little info on desired outcome for this issue.
Thanks for taking the time to enter an issue. However, it seems that there aren't enough details here for this issue to be actionable.
When issues are created, we need details such as:
- Which Fluent UI component is causing the issue
- Which package name and version the component is from
- Specific, complete steps to reproduce the issue
- What behaviors and attributes are missing or incorrect
- What you expected and what is actually happening
- Confirmation that the problem reproduces in isolation
Without a clear understanding of these details, it's not possible to take clear action on issues. We are unable to meet your expectations, properly address the root cause, and make changes without affecting the expectations of other consumers.
Please provide these additional details as you are able. The default issue template provides an outline of these details and is viewable when creating a new issue. Additionally, if this is an accessibility issue, please see Accessibility Troubleshooting in our wiki for more guidance. If these details cannot be provided, please kindly close the issue.
Thank you for your patience.
Go the exact same problem. The expected outcome of this scenario would be that the text that we put on the ComboBox would show on the ComboBox. However, the value disappears if that value doesn't belong to the options available on the dropdowns of the ComboBox.
This issue has been automatically marked as stale because it has marked as requiring actionable feedback but has not had any activity for 2 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fluent UI!
after a little digging this looks like what might be happening.
The use of onChange causes ComboBox to behave as a controlled component. This means it's expecting another component (usually it's parent) to store/control the current value. This effectively disables the "allowFreeForm" behavior where new options can be added to the list, since onChange sets up combobox to expect a parent to control the list through the use of the options prop, allowFreeForm does nothing.
Here's the line of code that controls the behavior: https://github.com/microsoft/fluentui/blob/0ecf05881398b6b72c20a20e1cd905a17f057fba/packages/react/src/components/ComboBox/ComboBox.tsx#L1173