Skip to content

Commit

Permalink
update ngx-mat-select-search to version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
macjohnny committed Jun 16, 2020
1 parent fc1484d commit c26d086
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 16 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@angular/platform-browser-dynamic": "8.2.14",
"@angular/router": "8.2.14",
"core-js": "^2.6.1",
"ngx-mat-select-search": "^2.2.0",
"ngx-mat-select-search": "^3.0.0",
"rxjs": "6.5.4",
"zone.js": "~0.9.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ <h2>Examples</h2>

<app-tooltip-select-all-example></app-tooltip-select-all-example>

<app-infinite-scroll-example></app-infinite-scroll-example>

<span class="version-info">
ngx-mat-select-search Version: {{matSelectSearchVersion}} <br/>
Material Version: {{version.full}}
Expand Down
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { CustomClearIconExampleComponent } from './examples/03-custom-clear-icon
import { MultipleSelectionExampleComponent } from './examples/02-multiple-selection-example/multiple-selection-example.component';
import { SingleSelectionExampleComponent } from './examples/01-single-selection-example/single-selection-example.component';
import { MultipleSelectionSelectAllExampleComponent } from './examples/06-multiple-selection-select-all-example/multiple-selection-select-all-example.component';
import { TooltipSelectAllExampleComponent } from './examples/07-tooltip-select-all-exemple/tooltip-select-all-example.component';
import { TooltipSelectAllExampleComponent } from './examples/07-tooltip-select-all-example/tooltip-select-all-example.component';
import { InfiniteScrollExampleComponent } from './examples/08-infinite-scroll-example/infinite-scroll-example.component';


@NgModule({
Expand All @@ -28,7 +29,8 @@ import { TooltipSelectAllExampleComponent } from './examples/07-tooltip-select-a
OptionGroupsExampleComponent,
ServerSideSearchExampleComponent,
MultipleSelectionSelectAllExampleComponent,
TooltipSelectAllExampleComponent
TooltipSelectAllExampleComponent,
InfiniteScrollExampleComponent
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ <h3>Multiple selection</h3>
<p>
<mat-form-field>
<mat-select [formControl]="bankMultiCtrl" placeholder="Banks" [multiple]="true" #multiSelect>
<ngx-mat-select-search [formControl]="bankMultiFilterCtrl"></ngx-mat-select-search>
<mat-option>
<ngx-mat-select-search [formControl]="bankMultiFilterCtrl"></ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let bank of filteredBanksMulti | async" [value]="bank">
{{bank.name}}
</mat-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ <h3>Single selection with custom clear icon</h3>
<p>
<mat-form-field>
<mat-select [formControl]="bankCtrl" placeholder="Bank" #singleSelect>
<ngx-mat-select-search *ngIf="true" [formControl]="bankFilterCtrl" [preventHomeEndKeyPropagation]="true">
<mat-icon ngxMatSelectSearchClear>delete</mat-icon>
</ngx-mat-select-search>
<mat-option>
<ngx-mat-select-search *ngIf="true" [formControl]="bankFilterCtrl" [preventHomeEndKeyPropagation]="true">
<mat-icon ngxMatSelectSearchClear>delete</mat-icon>
</ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let bank of filteredBanks | async" [value]="bank">
{{bank.name}}
</mat-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ <h3>Single selection with option groups</h3>
<p>
<mat-form-field>
<mat-select [formControl]="bankGroupsCtrl" placeholder="Bank" #singleSelect>
<ngx-mat-select-search [formControl]="bankGroupsFilterCtrl"></ngx-mat-select-search>
<mat-option>
<ngx-mat-select-search [formControl]="bankGroupsFilterCtrl"></ngx-mat-select-search>
</mat-option>
<mat-optgroup *ngFor="let group of filteredBankGroups | async" [label]="group.name">
<mat-option *ngFor="let bank of group.banks" [value]="bank">
{{bank.name}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ <h3>Multiple selection with 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"></ngx-mat-select-search>
<mat-option>
<ngx-mat-select-search [showToggleAllCheckbox]="true" (toggleAll)="toggleSelectAll($event)" [formControl]="bankMultiFilterCtrl"></ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let bank of filteredBanksMulti | async" [value]="bank">
{{bank.name}}
</mat-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ <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>
<ngx-mat-select-search [showToggleAllCheckbox]="true" (toggleAll)="toggleSelectAll($event)"
[formControl]="bankMultiFilterCtrl" [toggleAllCheckboxTooltipMessage]="tooltipMessage"
[toogleAllCheckboxTooltipPosition]="'above'"></ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let bank of filteredBanksMulti | async" [value]="bank">
{{bank.name}}
</mat-option>
</mat-select>
</mat-form-field>
</p>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h3>Integration with <a href="https://github.com/orizens/ngx-infinite-scroll" target="_blank">ngx-infinite-scroll</a></h3>

<p>
Selected Bank: {{ctrl?.value}}
</p>

<mat-form-field>
<mat-select msInfiniteScroll (infiniteScroll)="getNextBatch()"
[formControl]="ctrl"
placeholder="Select Something"
(valueChange)="onChange($event)">
<mat-option>
<!--disableScrollToActiveOnOptionsChanged should be set to true-->
<ngx-mat-select-search
[formControl]="searchCtrl"
placeholderLabel="search"
[disableScrollToActiveOnOptionsChanged]="true"
noEntriesFoundLabel="No entry matches">
</ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let option of options$ | async" [value]="option">
{{option}}
</mat-option>
</mat-select>
</mat-form-field>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { BehaviorSubject, Subject, Subscription } from 'rxjs';
import { scan, takeUntil } from 'rxjs/operators';

/**
* Based upon: https://stackblitz.com/edit/mat-select-search-with-infinity-scroll
*/
@Component({
selector: 'app-infinite-scroll-example',
templateUrl: './infinite-scroll-example.component.html',
styleUrls: ['./infinite-scroll-example.component.scss']
})
export class InfiniteScrollExampleComponent implements OnInit, OnDestroy {
// Mocks some sort of backend data source
mockBankList = Array.from({ length: 1000 }).map((_, i) => `Bank ${i}`);
private _data = new BehaviorSubject<any[]>(this.mockBankList);
data$ = this._data.asObservable();

ctrl: FormControl = new FormControl();
searchCtrl: FormControl = new FormControl();

subscriptions: Subscription[] = [];
_options = new BehaviorSubject([]);
options$ = this._options.asObservable().pipe(
scan((acc, curr) => {
if (!acc || !curr) {
return [];
}
return [...acc, ...curr];
}, [])
);
offset = 0;
limit = 20;
/**
* Holds the option matches
* a subset of this data is selected
* using the offset and limit
*/
data = [];

/** Subject that emits when the component has been destroyed. */
protected _onDestroy = new Subject<void>();

constructor() { }

ngOnInit() {
this.data$.pipe(
takeUntil(this._onDestroy)
).subscribe({
next: (data) => {
console.log('Ingested data changed');
this.data = data;
this.offset = 0;
this._options.next(null);
this.getNextBatch();
}
});

this.searchCtrl
.valueChanges
.pipe(
takeUntil(this._onDestroy)
)
.subscribe((val) => this.onSearchChange(val));

this.options$
.pipe(
takeUntil(this._onDestroy)
).
subscribe((val) => console.log(`New view array contains ${val.length} items`));
}

ngOnDestroy(): void {
this._onDestroy.next();
this._onDestroy.complete();
}

onChange(e): void {
console.log(`Value Changed: ${e}`);
}

onSearchChange(e): void {
console.log(`Search Changed: ${e}`);
let val = e ? e.trim() : null;
if (!val) {
// Empty search, returns everything
this._data.next(this.mockBankList);
return;
} else {
val = val.toLowerCase();
}

const matches = this.mockBankList.filter((i) => i.toLowerCase().indexOf(val.toLowerCase()) > -1);
this._data.next(matches);
}

/**
* Used for selecting next batch
* for ngx-infinite-scroll
*/
getNextBatch(): void {
const results = this.data.slice(this.offset, this.offset + this.limit);
this._options.next(results);
this.offset += this.limit;
}
}

0 comments on commit c26d086

Please sign in to comment.