Combo Box options selected by default don't unselect/uncheck when clicked in Multiselect
Bug Report
- Package version(s): (5.82.2)
- Browser and OS versions: (All browsers)
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? (Yes)
Requested priority: (High)
Products/sites affected: (if applicable)
Describe the issue:
Combo Box options multi select box doesn't uncheck on first click
Actual behavior:
Combo box option doesn't uncheck when clicked the first time. We have to clicked on second time to uncheck them. The issue is with the selected property of the option which is set to true on first click when it should set to false. It can be seen here in the Multiselect uncontrolled or controlled example. https://developer.microsoft.com/en-us/fabric#/components/ComboBox
Expected behavior:
Combo box option should be uncheck when clicked the first time and selected property set to false
Thanks for reporting this @AsishP, that's a great catch. This should definitely be fixed. If you're willing to submit a PR, we'd be happy to review and shepherd it in. @jspurlin @christiango FYI
I think the bug is here:
https://github.com/OfficeDev/office-ui-fabric-react/blob/master/packages/office-ui-fabric-react/src/components/ComboBox/ComboBox.tsx#L778
The selection logic uses a key selected on the option object to indicate whether or not its selected. On first pass this is undefined and since we do a !option.selected the first click will always set it to true. The fix is likely to set the flags accordingly when initialized on the object so that state is correct.
It looks like we also support async options fetching via _onResolveOptions so any fix should make sure that this works as expected in both scenarios.
Thanks @Jahnp, am happy to contribute. Will start this weekend. Shouldn't take much time.
@KevinTCoughlin, thanks for the heads up. Will post any queries here while looking into it.
Hi all, I was able to fix the combo box selection toggle for first click. The fix is that when option.selected is null, then check selectedIndices array to see if an index is present and then negate that value. Hopefully this logic will not fail for any other cases. If it sounds good, please let me know and will submit a PR soon.
@KevinTCoughlin, seems like in _onResolveOptions method, the currentOptions array is filled with a newOptions array. So, don't think there would be any issue as the above fix is also updating the selectedIndices array which would return the most updated options array in onResolveOptions too.. Could you please confirm.
Has this issue been resolved? i'm experiencing the same issue. Thanks
@AsishP is there a way you could share your fix. It's been two weeks since you brought up the issue and it doesn't seem like there's any hurry to fix.
@jberu624, sorry for the delay, the issue was fixed but waiting for some feedback for my comment above.
Pull Request created now with the fix.
@KevinTCoughlin Jiggling the chain on this one so we can keep things moving along. :) Can you respond to @AsishP 's query above? Thanks!
@AsishP I pulled your fix and fixed my issue. I'm not really sure what to do next.
Thanks @jberu624. Sorry I don't have merge rights. @michaelangotti, can we merge the code or wait for @KevinTCoughlin reply?
@natalieethell Can you help move this one along in @KevinTCoughlin's absence?
@michaelangotti Definitely. The change looks good on my end. I'll go ahead and merge it.