fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Combo Box options selected by default don't unselect/uncheck when clicked in Multiselect

Open AsishP opened this issue 8 years ago • 12 comments

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

AsishP avatar Apr 27 '18 00:04 AsishP

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

Jahnp avatar Apr 27 '18 03:04 Jahnp

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.

KevinTCoughlin avatar Apr 27 '18 16:04 KevinTCoughlin

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.

AsishP avatar Apr 28 '18 02:04 AsishP

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.

AsishP avatar Apr 28 '18 06:04 AsishP

Has this issue been resolved? i'm experiencing the same issue. Thanks

jberu624 avatar May 09 '18 08:05 jberu624

@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 avatar May 12 '18 02:05 jberu624

@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.

AsishP avatar May 12 '18 11:05 AsishP

@KevinTCoughlin Jiggling the chain on this one so we can keep things moving along. :) Can you respond to @AsishP 's query above? Thanks!

michaelangotti avatar May 23 '18 21:05 michaelangotti

@AsishP I pulled your fix and fixed my issue. I'm not really sure what to do next.

jberu624 avatar May 24 '18 00:05 jberu624

Thanks @jberu624. Sorry I don't have merge rights. @michaelangotti, can we merge the code or wait for @KevinTCoughlin reply?

AsishP avatar May 24 '18 05:05 AsishP

@natalieethell Can you help move this one along in @KevinTCoughlin's absence?

michaelangotti avatar May 24 '18 18:05 michaelangotti

@michaelangotti Definitely. The change looks good on my end. I'll go ahead and merge it.

natalieethell avatar May 24 '18 18:05 natalieethell