From 0c06de8df43f1186bd3d460d842e1930faf46f62 Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Fri, 4 Feb 2022 18:02:48 -0500 Subject: [PATCH 1/2] feat: add minor multiselect improvements --- .../multi-select/multi-select.component.scss | 4 +++ .../multi-select/multi-select.component.ts | 32 +++++++++++++++---- .../src/multi-select/multi-select.module.ts | 4 ++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/projects/components/src/multi-select/multi-select.component.scss b/projects/components/src/multi-select/multi-select.component.scss index 694d3af32..a3ccc2032 100644 --- a/projects/components/src/multi-select/multi-select.component.scss +++ b/projects/components/src/multi-select/multi-select.component.scss @@ -30,6 +30,10 @@ height: 34px; border-radius: 6px; + &.disabled { + cursor: not-allowed; + } + &.extra-small { height: 30px; } diff --git a/projects/components/src/multi-select/multi-select.component.ts b/projects/components/src/multi-select/multi-select.component.ts index c0ab74510..93b578604 100644 --- a/projects/components/src/multi-select/multi-select.component.ts +++ b/projects/components/src/multi-select/multi-select.component.ts @@ -53,15 +53,23 @@ import { MultiSelectJustify } from './multi-select-justify';
- +{{ triggerValues.selectedItemsCount - 1 }}+{{ triggerValues.overflowItemsCount }}
@@ -262,6 +270,10 @@ export class MultiSelectComponent implements ControlValueAccessor, AfterConte this.propagateControlValueChangeOnTouch = onTouch; } + public setDisabledState(isDisabled?: boolean): void { + this.disabled = isDisabled ?? false; + } + private setSelection(selected: V[]): void { this.selected = selected; this.setTriggerLabel(); @@ -273,7 +285,7 @@ export class MultiSelectComponent implements ControlValueAccessor, AfterConte if (this.triggerLabelDisplayMode === TriggerLabelDisplayMode.Placeholder) { this.triggerValues$ = of({ label: this.placeholder, - selectedItemsCount: 0 + overflowItemsCount: 0 }); return; @@ -282,10 +294,17 @@ export class MultiSelectComponent implements ControlValueAccessor, AfterConte this.triggerValues$ = this.allOptions$?.pipe( map(options => { const selectedItems: SelectOptionComponent[] = options.filter(item => this.isSelectedItem(item)); + const isMultiSelection = selectedItems.length > 1; return { label: this.getLabel(selectedItems), - selectedItemsCount: selectedItems.length + overflowItemsCount: isMultiSelection ? selectedItems.length - 1 : 0, + overflowLabel: isMultiSelection + ? selectedItems + .slice(1) + .map(item => item.label) + .join(', ') + : undefined }; }) ); @@ -307,7 +326,8 @@ export class MultiSelectComponent implements ControlValueAccessor, AfterConte interface TriggerValues { label: string | undefined; - selectedItemsCount: number; + overflowItemsCount: number; + overflowLabel?: string; } export const enum TriggerLabelDisplayMode { diff --git a/projects/components/src/multi-select/multi-select.module.ts b/projects/components/src/multi-select/multi-select.module.ts index f0462ba0d..e4eab85fd 100644 --- a/projects/components/src/multi-select/multi-select.module.ts +++ b/projects/components/src/multi-select/multi-select.module.ts @@ -8,6 +8,7 @@ import { LabelModule } from '../label/label.module'; import { LoadAsyncModule } from '../load-async/load-async.module'; import { PopoverModule } from '../popover/popover.module'; import { TraceSearchBoxModule } from '../search-box/search-box.module'; +import { TooltipModule } from '../tooltip/tooltip.module'; import { MultiSelectComponent } from './multi-select.component'; @NgModule({ @@ -20,7 +21,8 @@ import { MultiSelectComponent } from './multi-select.component'; TraceSearchBoxModule, ButtonModule, LoadAsyncModule, - TraceCheckboxModule + TraceCheckboxModule, + TooltipModule ], declarations: [MultiSelectComponent], exports: [MultiSelectComponent] From e845a2ce692776a78b52f1daecfd8ec8c7256567 Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Fri, 4 Feb 2022 18:17:59 -0500 Subject: [PATCH 2/2] test: fix tests --- .../multi-select/multi-select.component.test.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/components/src/multi-select/multi-select.component.test.ts b/projects/components/src/multi-select/multi-select.component.test.ts index 54f7a1526..b293743c5 100644 --- a/projects/components/src/multi-select/multi-select.component.test.ts +++ b/projects/components/src/multi-select/multi-select.component.test.ts @@ -80,7 +80,8 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('x', { x: { label: selectionOptions[1].label, - selectedItemsCount: 1 // Selected element is 1 as set in hostProps + overflowItemsCount: 0, + overflowLabel: undefined } }); }); @@ -116,7 +117,8 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('x', { x: { label: selectionOptions[1].label, - selectedItemsCount: 2 + overflowItemsCount: 1, + overflowLabel: 'third' } }); }); @@ -159,7 +161,8 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('x', { x: { label: 'second', - selectedItemsCount: 2 + overflowItemsCount: 1, + overflowLabel: 'third' } }); }); @@ -232,7 +235,8 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('x', { x: { label: 'second', - selectedItemsCount: 2 + overflowItemsCount: 1, + overflowLabel: 'third' } }); }); @@ -368,7 +372,7 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('(x|)', { x: { label: 'Placeholder', - selectedItemsCount: 0 + overflowItemsCount: 0 } }); }); @@ -398,7 +402,7 @@ describe('Multi Select Component', () => { expectObservable(spectator.component.triggerValues$).toBe('x', { x: { label: selectionOptions[1].label, - selectedItemsCount: 1 + overflowItemsCount: 0 } }); });