+
+
+
+ All
+
+
+
+
+
implements AfterContentInit, OnChanges {
@Input()
public justify?: SelectJustify;
+ @Input()
+ public showAllOptionControl?: boolean = false;
+
@Input()
public triggerLabelDisplayMode: TriggerLabelDisplayMode = TriggerLabelDisplayMode.Selection;
@@ -113,6 +125,33 @@ export class MultiSelectComponent implements AfterContentInit, OnChanges {
this.setTriggerLabel();
}
+ public onAllSelectionChange(): void {
+ this.selected = this.areAllOptionsSelected() ? [] : this.items!.map(item => item.value); // Select All or none
+ this.setSelection();
+ }
+
+ public areAllOptionsSelected(): boolean {
+ return this.selected !== undefined && this.items !== undefined && this.selected.length === this.items.length;
+ }
+
+ public onSelectionChange(item: SelectOptionComponent): void {
+ this.selected = this.isSelectedItem(item)
+ ? this.selected?.filter(value => value !== item.value)
+ : (this.selected ?? []).concat(item.value);
+
+ this.setSelection();
+ }
+
+ public isSelectedItem(item: SelectOptionComponent): boolean {
+ return this.selected !== undefined && this.selected.filter(value => value === item.value).length > 0;
+ }
+
+ private setSelection(): void {
+ this.setTriggerLabel();
+ this.selected$ = this.buildObservableOfSelected();
+ this.selectedChange.emit(this.selected);
+ }
+
private setTriggerLabel(): void {
if (this.triggerLabelDisplayMode === TriggerLabelDisplayMode.Placeholder) {
this.triggerLabel = this.placeholder;
@@ -130,10 +169,6 @@ export class MultiSelectComponent implements AfterContentInit, OnChanges {
}
}
- public isSelectedItem(item: SelectOptionComponent): boolean {
- return this.selected !== undefined && this.selected.filter(value => value === item.value).length > 0;
- }
-
private buildObservableOfSelected(): Observable[] | undefined> {
if (!this.items) {
return EMPTY;
@@ -145,16 +180,6 @@ export class MultiSelectComponent implements AfterContentInit, OnChanges {
);
}
- public onSelectionChange(item: SelectOptionComponent): void {
- this.selected = this.isSelectedItem(item)
- ? this.selected?.filter(value => value !== item.value)
- : (this.selected ?? []).concat(item.value);
-
- this.setTriggerLabel();
- this.selected$ = this.buildObservableOfSelected();
- this.selectedChange.emit(this.selected);
- }
-
// Find the select option object for a value
private findItems(value: V[] | undefined): SelectOption[] | undefined {
if (this.items === undefined) {
diff --git a/projects/components/src/multi-select/multi-select.module.ts b/projects/components/src/multi-select/multi-select.module.ts
index 2382650e9..84e413994 100644
--- a/projects/components/src/multi-select/multi-select.module.ts
+++ b/projects/components/src/multi-select/multi-select.module.ts
@@ -1,6 +1,7 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
+import { DividerModule } from '../divider/divider.module';
import { IconModule } from '../icon/icon.module';
import { LabelModule } from '../label/label.module';
import { LetAsyncModule } from '../let-async/let-async.module';
@@ -8,7 +9,7 @@ import { PopoverModule } from '../popover/popover.module';
import { MultiSelectComponent } from './multi-select.component';
@NgModule({
- imports: [FormsModule, CommonModule, IconModule, LabelModule, LetAsyncModule, PopoverModule],
+ imports: [FormsModule, CommonModule, IconModule, LabelModule, LetAsyncModule, PopoverModule, DividerModule],
declarations: [MultiSelectComponent],
exports: [MultiSelectComponent]
})