Skip to content

Commit

Permalink
fix selection of different instances of same object when using `multi…
Browse files Browse the repository at this point in the history
…ple` (#216)

* #215: fix selection of different instances of same object when using `multiple`

* Apply suggestions from code review

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>
  • Loading branch information
probert94 and macjohnny authored Mar 4, 2020
1 parent b6b6ba0 commit fbfe2d9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/mat-select-search/mat-select-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, AfterViewIni
}
const optionValues = this.matSelect.options.map(option => option.value);
this.previousSelectedValues.forEach(previousValue => {
if (values.indexOf(previousValue) === -1 && optionValues.indexOf(previousValue) === -1) {
if (!values.some(v => this.matSelect.compareWith(v, previousValue))
&& !optionValues.some(v => this.matSelect.compareWith(v, previousValue))) {
// if a value that was selected before is deselected and not found in the options, it was deselected
// due to the filtering, so we restore it.
values.push(previousValue);
Expand Down

0 comments on commit fbfe2d9

Please sign in to comment.