Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c5346f

Browse files
ZainAsif767Zain Asif
andauthoredSep 26, 2024
Enhance Dropdown with "No Record Found" State and Improved Search Functionality (#55)
* fix(tags-input): prevent dropdown from closing on tag selection - Added a flag to decide the default behavior that closes the dropdown on tag selection. - Related to a bug where users had to reopen the dropdown after each selection. * fix(tags-input): fixed for attribute * feat(dropdown): added a no record found message when searching for tags which are not available * refactor(dropdown): refactored the dropdown with requested changes * refactor(dropdown): removed unused styles * fix(dropdown): removed no results to show div from childTemplate --------- Co-authored-by: Zain Asif <zain.asif@iomechs.com>
1 parent 7bf80bb commit 9c5346f

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed
 
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
21
<ng-container
3-
*ngTemplateOutlet="dropDownTemplate; context: context">
4-
</ng-container>
2+
*ngTemplateOutlet="dropDownTemplate; context: context"
3+
></ng-container>
54

65
<!-- Default Tag Options Template -->
76
<ng-template #defaultTagOptionTemplate let-items="items" let-config="config">
87
<div class="angular-tags-dropdown">
98
<div class="angular-tags-dropdown__list">
10-
<ng-container *ngFor="let item of items, let i = index">
9+
<ng-container *ngFor="let item of items; let i = index">
1110
<div
1211
class="angular-tags-dropdown__list__item"
1312
(click)="onItemClicked(item)"
1413
tiKeyboardActiveClass="angular-tags-dropdown__list__item--active"
1514
[isKeyboardActiveItem]="item.tiKeyboardActive"
1615
(mouseenter)="showTooltip(item[config.hoverProperty])"
1716
(mouseleave)="hideTooltip()"
18-
>
19-
{{item[config.displayProperty]}}
17+
>
18+
{{ item[config.displayProperty] }}
2019
</div>
2120
</ng-container>
21+
<ng-container *ngIf="!items.length">
22+
<div>No results to show</div>
23+
</ng-container>
2224
</div>
2325
</div>
2426
</ng-template>
2527

26-
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="inputTooltipOverlayOrigin"
27-
[cdkConnectedOverlayOpen]="inputTooltipShown" [cdkConnectedOverlayPositions]="inputTooltipPositions">
28-
<div class="tooltip-main" *ngIf="tooltipForInput">
29-
{{ tooltipForInput }}
30-
</div>
28+
<ng-template
29+
cdkConnectedOverlay
30+
[cdkConnectedOverlayOrigin]="inputTooltipOverlayOrigin"
31+
[cdkConnectedOverlayOpen]="inputTooltipShown"
32+
[cdkConnectedOverlayPositions]="inputTooltipPositions"
33+
>
34+
<div class="tooltip-main" *ngIf="tooltipForInput">
35+
{{ tooltipForInput }}
36+
</div>
3137
</ng-template>

‎projects/angular-tags-input/src/lib/dropdown/dropdown.component.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
:host {
22
display: block;
3+
34
.angular-tags-dropdown {
45
padding: 8px 10px;
6+
57
&__list {
68
&__item {
79
padding: 8px 10px;
810
cursor: pointer;
911
transition: all ease 0.5s;
12+
1013
&:hover {
1114
background: #dcdcdc;
1215
}
16+
1317
&--active {
1418
background: #333;
1519
color: white;
@@ -21,4 +25,4 @@
2125

2226
.tooltip-main {
2327
padding: 20px;
24-
}
28+
}

‎projects/tags-input-demo/src/app/app.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ <h5 class="main__form__heading">4. Options with image</h5>
445445

446446

447447
<ng-template #ddNestedTemplate let-items="items" let-config="config" let-fns="fns">
448-
<div class="items-list" style="max-height: 250px; overflow-y: auto;padding-top: 8px;">
448+
<div class="items-list" *ngIf="items.length" style="max-height: 250px; overflow-y: auto;padding-top: 8px;">
449449
<div class="items-list__item" *ngFor="let item of items">
450450
<div tiKeyboardActiveClass="items-list__item__parent--selected" [isKeyboardActiveItem]="item.tiKeyboardActive"
451451
class="items-list__item__parent" (click)="fns.onItemClicked(item)" cdkOverlayOrigin #onHoverTrigger="cdkOverlayOrigin"
@@ -461,8 +461,11 @@ <h5 class="main__form__heading">4. Options with image</h5>
461461
<ng-container
462462
*ngTemplateOutlet="ddNestedChildrenTemplate; context: {items: item[config.nestedTagProperty], config: config, fns: fns}">
463463
</ng-container>
464+
</div>
465+
</div>
466+
<div class="items-list__item" *ngIf="!items.length">
467+
<span>No results to show</span>
464468
</div>
465-
</div>
466469
</ng-template>
467470

468471
<ng-template #ddNestedChildrenTemplate let-items="items" let-fns="fns" let-config="config">

0 commit comments

Comments
 (0)
Please sign in to comment.