Skip to content

Commit

Permalink
feat(dropdown): truncate long text in dropdown (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
vt-allianz authored and GitHub Enterprise committed Mar 25, 2022
1 parent bb2c638 commit 40a53a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions projects/ng-aquila/src/dropdown/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,12 @@ describe('NxDropdownComponent', () => {
dropdownElement.style.width = '200px';
}));

it('should use the whole viewport width', fakeAsync(() => {
it('should not use the whole viewport width', fakeAsync(() => {
openDropdownByClick();
fixture.detectChanges();
flush();

expect(getDropdown()!.clientWidth).toBe(document.body.clientWidth - dropdownInstance._overlayViewportMargin);
expect(getDropdown()!.clientWidth).toBe(453);
}));
});

Expand Down
9 changes: 6 additions & 3 deletions projects/ng-aquila/src/dropdown/item/dropdown-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

<ng-template #contentTemplate>
<div class="nx-dropdown-results__option-label">
<span #content (cdkObserveContent)="_onLabelChange()">
<div #content (cdkObserveContent)="_onLabelChange()" [nxTooltip]="viewValue?.length > 35 ? viewValue : null" class="ellipsis">
<ng-content></ng-content>
</span>
<ng-container *ngIf="_isContentEmpty(content)"> {{_formattedValue}} </ng-container>
</div>

<div [nxTooltip]="value?.length > 35 ? value : null" class="ellipsis">
<ng-container *ngIf="_isContentEmpty(content)"> {{_formattedValue }} </ng-container>
</div>
</div>
</ng-template>
7 changes: 7 additions & 0 deletions projects/ng-aquila/src/dropdown/item/dropdown-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ nx-checkbox {
}
}
}

.ellipsis {
max-width: 35ch;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

0 comments on commit 40a53a8

Please sign in to comment.