Skip to content
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 @@ -54,11 +54,20 @@
display: flex;
width: 100%;
align-items: center;
padding-left: 8px;

.trigger-label {
@include body-2-medium();
padding-left: 8px;
width: calc(100% - 32px - 52px);
flex-grow: 1;
}

.trigger-more-items {
padding: 0 6px;
background-color: $gray-2;
border-radius: 4px;
margin-left: 5px;
Copy link
Contributor

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!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

max-width: 52px;
}

.trigger-icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}));

Expand Down Expand Up @@ -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 });
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test this from Dom. Example:

expect(spectator.query('.trigger-more-items')).toHaveText('6')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

expect(spectator.query('.trigger-more-items')?.innerHTML).toBe('+5');

spectator.setHostInput({
searchMode: MultiSelectSearchMode.Disabled
Expand Down Expand Up @@ -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();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
>
<ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.Small}"></ht-icon>
</div>
</div>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -236,10 +240,13 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges {
);
if (selectedItems === undefined || selectedItems.length === 0) {
this.triggerLabel = this.placeholder;
this.selectedItemsCount = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can move this assignment out of the condition then collapse the conditional

this.selectedItemsCount = selectedItems?.length ?? 0;
this.triggerLabel = this.selectedItemsCount === 0 ? this.placeholder : selectedItems[0].label;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

} 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;
}
}
}
Expand Down