Dropdown mutates the arrays passed in options. {Selected: true} flags are not cleared.
Bug Report
- Package version(s): Dropdown: 4.30.0 Added multi-select support for dropdown (#2386)
- Browser and OS versions: all
Priorities
Are you willing to submit a PR to fix? (Yes, No) No
Requested priority: (Blocking, High, Normal, Low) Normal
Describe the issue:
Dropdown mutates the arrays passed in options by adding a property selected: true to each choice on selection. Also, it does not clear the selected flag after the user picked up a different choice.
Deep cloning the array before passing to options prevented the unexpected state mutations.
Actual behavior:
this.setState({
dropOptions: [
{key: 'A', text: 'Option a'},
{key: 'B', text: 'Option b'}
]
});
<Dropdown
options={this.state.dropOptions}
/>
After selecting both options in GUI, the console.log(this.state.dropOptions) will output:
[
{"key":"A","text":"Option a","itemType":0,"selected":true},
{"key":"B","text":"Option b","itemType":0,"selected":true}
]
This issue is very critical. When developer uses dropdown as a controlled element (using selectedKey props), the selection on a lower option won't trigger UI change.
Example: [A, B, C, D]. Current selection is A, when user selects D, dropdown still shows A
Follow-up: Using the new Prop: SelectedKeys will work well, while using the SelectedKey will have this problem.
Anyway, I created a seperate issue #2471
Fixed
Thanks a lot!