Skip to content
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

added remove all on select #816

Merged
merged 6 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
</button>
</ng-template>
</ng-container>
<ng-container *ngIf="multiple && showRemoveAll && items?.length">
<ng-template ng-header-tmp>
<button
(click)="onRemoveAll()"
class="go-select__select-all-button"
[ngClass]="{ 'go-select__select-all-button--dark' : theme === 'dark' }">
Remove All
</button>
grahamhency marked this conversation as resolved.
Show resolved Hide resolved
</ng-template>
</ng-container>
<ng-container *ngIf="goSelectSelectedOption">
<ng-template ng-label-tmp let-item="item">
<ng-container *ngTemplateOutlet="goSelectSelectedOption; context: { $implicit: item }"></ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,19 @@ describe('GoSelectComponent', () => {
expect(component.control.value).toEqual([1, 2, 3]);
});
});

describe('onRemoveAll()', () => {
grahamhency marked this conversation as resolved.
Show resolved Hide resolved
it('uses bindValue to get value if bindValue exists', () => {
grahamhency marked this conversation as resolved.
Show resolved Hide resolved
component.bindValue = 'id';
component.items = [
{ id: 1, label: 'Label 1' },
{ id: 2, label: 'Label 2' },
{ id: 3, label: 'Label 3' }
];

component.onRemoveAll();
grahamhency marked this conversation as resolved.
Show resolved Hide resolved

expect(component.control.value).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class GoSelectComponent implements OnInit {
@Input() placeholder: string;
@Input() searchable: boolean = true;
@Input() showSelectAll: boolean = true;
@Input() showRemoveAll: boolean = false;
grahamhency marked this conversation as resolved.
Show resolved Hide resolved
@Input() theme: 'light' | 'dark' = 'light';
@Input() typeahead?: Subject<string>;
@Input() typeToSearchText: string = 'Type to Search';
Expand All @@ -56,6 +57,10 @@ export class GoSelectComponent implements OnInit {
this.control.patchValue(this.items.map((item: any) => this.bindValue ? item[this.bindValue] : item));
}

onRemoveAll(): void {
this.control.reset();
}
grahamhency marked this conversation as resolved.
Show resolved Hide resolved

onScrollToEnd(): void {
if (this.virtualScroll) {
this.scrollToEnd.emit();
Expand Down