Skip to content

Commit f14a92c

Browse files
authored
fix: virtual scroll bounce (#115)
1 parent f5dc736 commit f14a92c

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

projects/ngb-filterable-dropdown-example/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ <h3>Lots and Lots of Items</h3>
132132
[autoClose]="autoClose"
133133
[disabled]="disabled"
134134
[items]="lotsOfItems"
135+
[itemHeight]="50"
135136
[loading]="loading"
136137
[searchInputPlaceholder]="searchInputPlaceholder"
137138
[selection]="lotsOfItemsSelection"

projects/ngb-filterable-dropdown/src/lib/ngb-custom-filterable-dropdown/ngb-custom-filterable-dropdown.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@
8383
</div>
8484
<cdk-virtual-scroll-viewport
8585
#viewport
86-
[itemSize]="ITEM_SIZE"
86+
[itemSize]="itemHeight"
8787
class="virtual-scroll-viewport"
8888
[hidden]="!filteredItems.length || loading"
8989
[style.height.px]="viewportHeight"
9090
>
91-
<div *cdkVirtualFor="let item of filteredItems">
91+
<div *cdkVirtualFor="let item of filteredItems" [style.height.px]="itemHeight">
9292
<button
9393
class="dropdown-item filterable-dropdown-item px-2"
9494
type="button"
95+
[style.height.px]="itemHeight"
9596
[ngbTooltip]="item"
9697
[disableTooltip]="!tooltips"
9798
[openDelay]="tooltipsOpenDelay"

projects/ngb-filterable-dropdown/src/lib/ngb-custom-filterable-dropdown/ngb-custom-filterable-dropdown.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ import { SelectionType } from "../selection-type";
5858
export class NgbCustomFilterableDropdownComponent implements OnInit, OnDestroy {
5959
public readonly SELECT = SelectionType.All;
6060
public readonly DESELECT = SelectionType.None;
61-
public readonly ITEM_SIZE = 40;
6261
public readonly MAX_HEIGHT = 280;
6362

6463
@Input() autoClose: boolean | "outside" | "inside" = "outside";
6564
@Input() allowCreateItem = false;
6665
@Input() customClickHandle = false;
6766
@Input() disabled = false;
67+
@Input() itemHeight = 37;
6868
@Input() searchInputPlaceholder = "Search";
6969
@Input() tooltips = false;
7070
@Input() tooltipsOpenDelay = 0;
@@ -201,9 +201,9 @@ export class NgbCustomFilterableDropdownComponent implements OnInit, OnDestroy {
201201
}
202202

203203
get viewportHeight(): number {
204-
return this.filteredItems.length * this.ITEM_SIZE > this.MAX_HEIGHT
204+
return this.filteredItems.length * this.itemHeight > this.MAX_HEIGHT
205205
? this.MAX_HEIGHT
206-
: this.filteredItems.length * this.ITEM_SIZE;
206+
: this.filteredItems.length * this.itemHeight;
207207
}
208208

209209
ngOnInit(): void {

projects/ngb-filterable-dropdown/src/lib/ngb-filterable-dropdown/ngb-filterable-dropdown.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[autoClose]="autoClose"
44
[disabled]="disabled"
55
[items]="items"
6+
[itemHeight]="itemHeight"
67
[loading]="loading"
78
[searchInputPlaceholder]="searchInputPlaceholder"
89
[selection]="selection"

projects/ngb-filterable-dropdown/src/lib/ngb-filterable-dropdown/ngb-filterable-dropdown.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class NgbFilterableDropdownComponent {
2424
@Input() autoClose: boolean | "outside" | "inside" = false;
2525
@Input() disabled = false;
2626
@Input() items: string | Array<string> = [];
27+
@Input() itemHeight = 37;
2728
@Input() loading = false;
2829
@Input() placeholder = "No Items Selected";
2930
@Input() searchInputPlaceholder = "Search";

0 commit comments

Comments
 (0)