bithost-gmbh / ngx-mat-select-search

Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
MIT License
647 stars 130 forks source link

BUG with select all checkbox #336

Closed ghost closed 1 year ago

ghost commented 3 years ago

Describe the bug Checkbox "Select all / unselect all" is checked even if not all list elements are checked

To Reproduce https://stackblitz.com/github/bithost-gmbh/ngx-mat-select-search-example

  1. click in "Tooltip on the Select All Checkbox"
  2. type "J"
  3. click checkbox "Select all / unselect all" -> "Bank J (Italy)" and checkbox "Select all / unselect all" is checked
  4. close list by clicking outside
  5. click in "Tooltip on the Select All Checkbox"
  6. ERROR -> checkbox "Select all / unselect all" is checked, although only "Bank J (Italy)" is checked

Expected behavior Checkbox "Select all / unselect all" shouldn't be checked

Screenshots

Desktop (please complete the following information): OS: Windows 10 Browser Google Chrome Version 92.0.4515.159

Smartphone (please complete the following information):

Additional context

macjohnny commented 3 years ago

do you want to fix the examples?

ghost commented 3 years ago

I only mentioned the examples, because it's the same behavior as in my application.

As you can see below, I added[toggleAllCheckboxChecked]="allSelectedChecked.locations" to my ngx-mat-select-search. For test purposes I added (focus)="onFocusFilter()" to my mat-select with a console.log('----- onFocusFilter() this.allSelectedChecked', this.allSelectedChecked['locations']); Even if this.allSelectedChecked['locations'] is false, the all checkbox is checked.

<mat-select multiple (focus)="onFocusFilter()" [ngModel]="inputFields?.locations" (ngModelChange)="inputFields.locations = $event; filtersChanged()">
  <mat-option>
    <ngx-mat-select-search [showToggleAllCheckbox]="true" (toggleAll)="toggleAllSelection($event, 'locations'); filtersChanged()"
                           [toggleAllCheckboxChecked]="allSelectedChecked.locations"
                           [toggleAllCheckboxTooltipMessage]="translations?.selectUnselectAll" [toogleAllCheckboxTooltipPosition]="'above'"
                           [alwaysRestoreSelectedOptionsMulti]="true" [formControl]="locationFilterCtrl"
                           placeholderLabel="{{ translations?.search }}" noEntriesFoundLabel="{{ translations?.noResultsFound }}">
      <mat-icon ngxMatSelectSearchClear>clear</mat-icon>
    </ngx-mat-select-search>
  </mat-option>
  <mat-option *ngFor="let location of filterOptionsFiltered?.locations"
              [value]="location?.id">
    {{ location?.name }}
  </mat-option>
</mat-select>
AhsanAyaz commented 1 year ago

@macjohnny can you mark this issue for hacktoberfest? Thanks

macjohnny commented 1 year ago

@AhsanAyaz I added the topic "hacktoberfest" to this repo, this should be enough, right?

AhsanAyaz commented 1 year ago

@macjohnny , yeah I believe so! And thanks 🙂