primefaces / primereact

The Most Complete React UI Component Library
https://primereact.org
MIT License
6.68k stars 1.01k forks source link

MultiSelect: Does not properly filter with groups if not using children name "items" #2856

Closed sleepybjr closed 2 years ago

sleepybjr commented 2 years ago

Describe the bug

If you use an optionGroupChildren parameter that isn't "item", then filtering will not work properly on grouped options for multiselect.

The issue is below. "items" is hardcoded so it will not replace the custom named children list with the filtered options, and you will always receive all the options of the group when filtering. https://github.com/primefaces/primereact/blob/7cb4bc1327ce4ff71cc1943c205fa5a2f8613020/components/lib/multiselect/MultiSelect.js#L489

It should be: filteredGroups.push({ ...optgroup, ...{ [props.optionGroupChildren] : filteredSubOptions } });

Reproducer

https://codesandbox.io/s/primereact-test-forked-0g9typ

PrimeReact version

8.0.1

React version

18.x

Language

ALL

Build / Runtime

Next.js

Browser(s)

No response

Steps to reproduce the behavior

  1. Open Codesanbox and attempt to filter "Berlin".
  2. Observe that all filter options for the group still remain.

Expected behavior

Only the filtered option should show, not the group of the filtered option.

melloware commented 2 years ago

I completely agree with your fix! Much appreciated for the report and the diagnosis!