Skip to content

fix: #18062 MultiSelect is removing previously selected values if sel… #18107

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/primeng/src/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,9 @@ export class MultiSelect extends BaseComponent implements OnInit, AfterViewInit,
? this.visibleOptions().filter((option) => !this.isValidOption(option) && this.isSelected(option))
: this.visibleOptions().filter((option) => this.isSelected(option) || this.isValidOption(option));

const optionValues = [...selectedDisabledOptions, ...visibleOptions].map((option) => this.getOptionValue(option));
const selectedOptionsBeforeSearch = this.filter && !this.allSelected() ? this.getAllVisibleAndNonVisibleOptions().filter((option) => this.isSelected(option) && this.isValidOption(option)) : [];

const optionValues = [...selectedOptionsBeforeSearch, ...selectedDisabledOptions, ...visibleOptions].map((option) => this.getOptionValue(option));
const value = [...new Set(optionValues)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For efficiency why not remove the conditional !this.allSelected() from const optionValues and update the conditional in const selectedOptionsBeforeSearch to (this.filter && !this.allSelected())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already refactored the code right after committing it. Thanks a lot for the review.


this.updateModel(value, event);
Expand Down
Loading