-
Notifications
You must be signed in to change notification settings - Fork 11
feat: adding count label on multiselect component #865
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
Changes from 3 commits
0dadf59
674363d
bacbd0f
d9260f3
c9d675a
58a3461
50a7f23
e98ba46
4a78354
c55b87a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,10 @@ describe('Multi Select Component', () => { | |
| expect(spectator.query('.trigger-label-container')).toExist(); | ||
| expect(spectator.query('.trigger-label')).toExist(); | ||
| expect(spectator.query('.trigger-icon')).toExist(); | ||
| expect(spectator.query('.trigger-more-items')).not.toExist(); | ||
|
|
||
| // Selected element is 1 as set in hostProps | ||
| expect(spectator.component.selectedItemsCount).toBe(1); | ||
|
|
||
| const popoverComponent = spectator.query(PopoverComponent); | ||
| expect(popoverComponent?.closeOnClick).toEqual(false); | ||
|
|
@@ -94,6 +98,8 @@ describe('Multi Select Component', () => { | |
|
|
||
| spectator.tick(); | ||
| const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true }); | ||
| expect(spectator.query('.trigger-more-items')).toExist(); | ||
| expect(spectator.component.selectedItemsCount).toBe(2); | ||
| expect( | ||
| selectedCheckboxElements.filter(checkboxElement => checkboxElement.getAttribute('ng-reflect-checked') === 'true') | ||
| .length | ||
|
|
@@ -127,6 +133,8 @@ describe('Multi Select Component', () => { | |
| expect(optionElements.length).toBe(6); | ||
|
|
||
| const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true }); | ||
| expect(spectator.query('.trigger-more-items')).toExist(); | ||
| expect(spectator.component.selectedItemsCount).toBe(2); | ||
| expect( | ||
| selectedCheckboxElements.filter(checkboxElement => checkboxElement.getAttribute('ng-reflect-checked') === 'true') | ||
| .length | ||
|
|
@@ -193,7 +201,9 @@ describe('Multi Select Component', () => { | |
|
|
||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| expect(onChange).toHaveBeenCalledWith([selectionOptions[1].value, selectionOptions[2].value]); | ||
| expect(spectator.query(LabelComponent)?.label).toEqual('second and 1 more'); | ||
| expect(spectator.query('.trigger-more-items')).toExist(); | ||
| expect(spectator.component.selectedItemsCount).toBe(2); | ||
| expect(spectator.query(LabelComponent)?.label).toEqual('second'); | ||
| flush(); | ||
| })); | ||
|
|
||
|
|
@@ -260,6 +270,8 @@ describe('Multi Select Component', () => { | |
| ).toBe(0); | ||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| expect(onChange).toHaveBeenLastCalledWith([]); | ||
| expect(spectator.query('.trigger-more-items')).not.toExist(); | ||
|
|
||
| expect(spectator.query(LabelComponent)?.label).toEqual('Select options'); | ||
|
|
||
| const allOptionElement = spectator.query('.select-all', { root: true }); | ||
|
|
@@ -268,10 +280,14 @@ describe('Multi Select Component', () => { | |
|
|
||
| spectator.tick(); | ||
| const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true }); | ||
| expect(spectator.query('.trigger-more-items')).toExist(); | ||
| expect(selectedCheckboxElements.length).toBe(6); | ||
|
|
||
| expect(onChange).toHaveBeenCalledWith(selectionOptions.map(option => option.value)); | ||
| expect(spectator.query(LabelComponent)?.label).toEqual('first and 5 more'); | ||
| expect(spectator.query(LabelComponent)?.label).toEqual('first'); | ||
|
|
||
| expect(spectator.component.selectedItemsCount).toBe(6); | ||
|
||
| expect(spectator.query('.trigger-more-items')?.innerHTML).toBe('+5'); | ||
|
|
||
| spectator.setHostInput({ | ||
| searchMode: MultiSelectSearchMode.Disabled | ||
|
|
@@ -314,6 +330,8 @@ describe('Multi Select Component', () => { | |
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| expect(onChange).toHaveBeenCalledWith([selectionOptions[1].value, selectionOptions[2].value]); | ||
| expect(spectator.query(LabelComponent)?.label).toEqual('Placeholder'); | ||
| expect(spectator.query('.trigger-more-items')).not.toExist(); | ||
| expect(spectator.component.selectedItemsCount).toBe(0); | ||
| flush(); | ||
| })); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,9 @@ import { MultiSelectJustify } from './multi-select-justify'; | |
| <ht-icon *ngIf="this.icon" [icon]="this.icon" [size]="this.iconSize"> </ht-icon> | ||
| <div *ngIf="!this.isIconOnlyMode()" class="trigger-label-container"> | ||
| <ht-label class="trigger-label" [label]="this.triggerLabel"></ht-label> | ||
| <span *ngIf="this.selectedItemsCount > 1" class="trigger-more-items" | ||
| >+{{ this.selectedItemsCount - 1 }}</span | ||
anandtiwary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > | ||
| <ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.Small}"></ht-icon> | ||
| </div> | ||
| </div> | ||
|
|
@@ -159,6 +162,7 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
|
|
||
| public popoverOpen: boolean = false; | ||
| public triggerLabel?: string; | ||
| public selectedItemsCount: number = 0; | ||
|
|
||
| public ngAfterContentInit(): void { | ||
| this.allOptions$ = this.allOptionsList !== undefined ? queryListAndChanges$(this.allOptionsList) : EMPTY; | ||
|
|
@@ -236,10 +240,13 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
| ); | ||
| if (selectedItems === undefined || selectedItems.length === 0) { | ||
| this.triggerLabel = this.placeholder; | ||
| this.selectedItemsCount = 0; | ||
|
||
| } else if (selectedItems.length === 1) { | ||
| this.triggerLabel = selectedItems[0].label; | ||
| this.selectedItemsCount = 1; | ||
| } else { | ||
| this.triggerLabel = `${selectedItems[0].label} and ${selectedItems.length - 1} more`; | ||
| this.triggerLabel = selectedItems[0].label; | ||
| this.selectedItemsCount = selectedItems.length; | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, we use margin/padding as multiple of 4. You may check that.
Otherwise
looks good to me!!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated