Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CMultiSelect should have value property #428

Open
niksajanjic opened this issue Jan 8, 2025 · 0 comments
Open

CMultiSelect should have value property #428

niksajanjic opened this issue Jan 8, 2025 · 0 comments

Comments

@niksajanjic
Copy link

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/

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant