-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update ngx-mat-select-search to version 2.2.0
- Loading branch information
Showing
8 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/examples/07-tooltip-select-all-exemple/tooltip-select-all-example.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h3>Tooltip on the Select All Checkbox</h3> | ||
<p> | ||
<mat-form-field color="accent"> | ||
<mat-select [formControl]="bankMultiCtrl" placeholder="Banks" [multiple]="true" #multiSelect> | ||
<ngx-mat-select-search [showToggleAllCheckbox]="true" (toggleAll)="toggleSelectAll($event)" | ||
[formControl]="bankMultiFilterCtrl" [toggleAllCheckboxTooltipMessage]="tooltipMessage" | ||
[toogleAllCheckboxTooltipPosition]="'above'"></ngx-mat-select-search> | ||
<mat-option *ngFor="let bank of filteredBanksMulti | async" [value]="bank"> | ||
{{bank.name}} | ||
</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
</p> |
3 changes: 3 additions & 0 deletions
3
src/app/examples/07-tooltip-select-all-exemple/tooltip-select-all-example.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
::ng-deep .ngx-mat-select-search-toggle-all-tooltip { | ||
font-size: 0.8em; | ||
} |
107 changes: 107 additions & 0 deletions
107
src/app/examples/07-tooltip-select-all-exemple/tooltip-select-all-example.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
import { ReplaySubject, Subject } from 'rxjs'; | ||
import { take, takeUntil } from 'rxjs/operators'; | ||
import { MatSelect } from '@angular/material/select'; | ||
|
||
import { Bank, BANKS } from '../demo-data'; | ||
|
||
@Component({ | ||
selector: 'app-tooltip-select-all-example', | ||
templateUrl: './tooltip-select-all-example.component.html', | ||
styleUrls: ['./tooltip-select-all-example.component.scss'] | ||
}) | ||
export class TooltipSelectAllExampleComponent implements OnInit, AfterViewInit, OnDestroy { | ||
|
||
/** list of banks */ | ||
protected banks: Bank[] = BANKS; | ||
|
||
/** control for the selected bank for multi-selection */ | ||
public bankMultiCtrl: FormControl = new FormControl(); | ||
|
||
/** control for the MatSelect filter keyword multi-selection */ | ||
public bankMultiFilterCtrl: FormControl = new FormControl(); | ||
|
||
/** list of banks filtered by search keyword */ | ||
public filteredBanksMulti: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1); | ||
|
||
public tooltipMessage = 'Select All / Unselect All'; | ||
|
||
@ViewChild('multiSelect', { static: true }) multiSelect: MatSelect; | ||
|
||
/** Subject that emits when the component has been destroyed. */ | ||
protected _onDestroy = new Subject<void>(); | ||
|
||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
// set initial selection | ||
this.bankMultiCtrl.setValue([this.banks[10], this.banks[11], this.banks[12]]); | ||
|
||
// load the initial bank list | ||
this.filteredBanksMulti.next(this.banks.slice()); | ||
|
||
// listen for search field value changes | ||
this.bankMultiFilterCtrl.valueChanges | ||
.pipe(takeUntil(this._onDestroy)) | ||
.subscribe(() => { | ||
this.filterBanksMulti(); | ||
}); | ||
} | ||
|
||
ngAfterViewInit() { | ||
this.setInitialValue(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this._onDestroy.next(); | ||
this._onDestroy.complete(); | ||
} | ||
|
||
toggleSelectAll(selectAllValue: boolean) { | ||
this.filteredBanksMulti.pipe(take(1), takeUntil(this._onDestroy)) | ||
.subscribe(val => { | ||
if (selectAllValue) { | ||
this.bankMultiCtrl.patchValue(val); | ||
} else { | ||
this.bankMultiCtrl.patchValue([]); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Sets the initial value after the filteredBanks are loaded initially | ||
*/ | ||
protected setInitialValue() { | ||
this.filteredBanksMulti | ||
.pipe(take(1), takeUntil(this._onDestroy)) | ||
.subscribe(() => { | ||
// setting the compareWith property to a comparison function | ||
// triggers initializing the selection according to the initial value of | ||
// the form control (i.e. _initializeSelection()) | ||
// this needs to be done after the filteredBanks are loaded initially | ||
// and after the mat-option elements are available | ||
this.multiSelect.compareWith = (a: Bank, b: Bank) => a && b && a.id === b.id; | ||
}); | ||
} | ||
|
||
protected filterBanksMulti() { | ||
if (!this.banks) { | ||
return; | ||
} | ||
// get the search keyword | ||
let search = this.bankMultiFilterCtrl.value; | ||
if (!search) { | ||
this.filteredBanksMulti.next(this.banks.slice()); | ||
return; | ||
} else { | ||
search = search.toLowerCase(); | ||
} | ||
// filter the banks | ||
this.filteredBanksMulti.next( | ||
this.banks.filter(bank => bank.name.toLowerCase().indexOf(search) > -1) | ||
); | ||
} | ||
|
||
} |