coreui-react icon indicating copy to clipboard operation
coreui-react copied to clipboard

CMultiSelect should have `value` property

Open niksajanjic opened this issue 1 year ago • 10 comments

This is PRO feature, but I don't have access to PRO repo therefore I created the issue here:

I think CMultiSelect should have value property just like any other form element. CDatePicker has date attribute, so I'm not concentrated on the name, but the ability to set the current value of the form component. Without that, this component is complicated to be implemented as controlled component.

The way it works at the moment is that we send options which can have selected property. That means, if we want to have a controlled component, we need to update options on every onChange or listen to value which can be updated from somewhere else and update selected options. That looks quite weird in my opinion.

I would expect the functionality to be more like this:

const [value, setValue] = useState([]);

<CMultiSelect
  onChange={selected => setValue(selected)}
  options={options}
  value={selected}
/>

The type of selected from onChange can always be an array, even when we select only one option. It should be internal logic of the component to calculate which options are selected from provided options and value. Also, value could have nested arrays that would correspond to nested options.

Similar component exist in Ant Design and it has value: https://ant.design/components/select

Also in Material UI, but they divided Select and Autocomplete components into 2 different ones, both have value: https://mui.com/material-ui/api/autocomplete/

niksajanjic avatar Jan 08 '25 17:01 niksajanjic

@niksajanjic I will check

mrholek avatar Jan 28 '25 15:01 mrholek

@mrholek Please also check the vue-pro package, as the same issue occurs there.

igoohd avatar Feb 03 '25 14:02 igoohd

Has anyone figured out a workaround for this?

errolNOTRS avatar Mar 25 '25 22:03 errolNOTRS

@niksajanjic @igoohd @errolNOTRS It will be added in one of the releases next month.

mrholek avatar Mar 25 '25 22:03 mrholek

@mrholek That's great news! Thanks!

errolNOTRS avatar Mar 25 '25 22:03 errolNOTRS

Thanks!

igoohd avatar Mar 28 '25 11:03 igoohd

Any updates on this? 😊

nynka avatar May 08 '25 09:05 nynka

@nynka it's done https://coreui.io/react/docs/forms/multi-select/api/#cmultiselect-value

mrholek avatar May 08 '25 09:05 mrholek

@nynka it's done https://coreui.io/react/docs/forms/multi-select/api/#cmultiselect-value

Awesome! 💯

nynka avatar May 08 '25 09:05 nynka

@nynka it's done https://coreui.io/react/docs/forms/multi-select/api/#cmultiselect-value

Was the vue-pro package updated as well? I didn’t see anything about it in the documentation.

igoohd avatar May 08 '25 10:05 igoohd

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Jul 07 '25 14:07 github-actions[bot]

@igoohd The value property has been available since version 5.11 in Vue.js.

mrholek avatar Jul 12 '25 17:07 mrholek