Skip to content

Commit d9f9fdb

Browse files
authored
feat: add virtualScroll option that could be disabled (#225)
* feat: add `virtualScroll` option that could be disabled
1 parent 316e5e4 commit d9f9fdb

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

packages/demo/src/examples/example10.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ <h2 class="bd-title">
1717
</span>
1818
</span>
1919
</h2>
20-
<div class="demo-subtitle">Virtual scroll will be used with a large set of data</div>
20+
<div class="demo-subtitle">
21+
Virtual Scroll will automatically be used with a large set of data.
22+
We recommend keeping this option enabled at all time, but in some cases you could also disable it via the <code>virtualScroll</code> option
23+
</div>
2124
</div>
2225
</div>
2326

packages/multiple-select-vanilla/src/MultipleSelectInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export class MultipleSelectInstance {
435435
offset = -1;
436436
}
437437

438-
if (rows.length > Constants.BLOCK_ROWS * Constants.CLUSTER_BLOCKS) {
438+
if (this.options.virtualScroll && rows.length > Constants.BLOCK_ROWS * Constants.CLUSTER_BLOCKS) {
439439
this.virtualScroll?.destroy();
440440

441441
const dropVisible = this.dropElm.style.display !== 'none';

packages/multiple-select-vanilla/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const DEFAULTS: Partial<MultipleSelectOption> = {
5555
useSelectOptionLabel: false,
5656
useSelectOptionLabelToHtml: false,
5757

58+
infiniteScroll: false,
59+
virtualScroll: true,
60+
5861
cssStyler: () => null,
5962
styler: () => false,
6063
textTemplate: (elm: HTMLOptionElement) => elm.innerHTML.trim(),

packages/multiple-select-vanilla/src/interfaces/multipleSelectOption.interface.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface MultipleSelectOption extends MultipleSelectLocale {
9191
/** Hide the option groupd checkboses. By default this is set to false. */
9292
hideOptgroupCheckboxes?: boolean;
9393

94-
/** Infinite Scroll will automatically reset the list (scroll back to top) whenever the scroll reaches the last item (end of the list) */
94+
/** Defaults to False, Infinite Scroll will automatically reset the list (scroll back to top) whenever the scroll reaches the last item (end of the list) */
9595
infiniteScroll?: boolean;
9696

9797
/** Whether or not Multiple Select open the select dropdown. */
@@ -178,6 +178,12 @@ export interface MultipleSelectOption extends MultipleSelectLocale {
178178
/** Defaults to False, same as "useSelectOptionLabel" but will also render html */
179179
useSelectOptionLabelToHtml?: boolean;
180180

181+
/**
182+
* Defaults to True, Virtual Scroll is used to improve performance with large set of data. The concept is to only render a subset
183+
* of the options (~200) at a time to avoid polluting the DOM, it will also consume less memory and improve overall performance of your application.
184+
*/
185+
virtualScroll?: boolean;
186+
181187
/** Define the width property of the dropdown list, support a percentage setting.By default this option is set to undefined. Which is the same as the select input field. */
182188
width?: number | string;
183189

playwright/e2e/methods01.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ test.describe('Methods 01 - getOptions()', () => {
4444
`"autoAdjustDropWidthByTextSize": false,`,
4545
`"adjustedHeightPadding": 10,`,
4646
`"useSelectOptionLabel": false,`,
47-
`"useSelectOptionLabelToHtml": false\n}`,
47+
`"useSelectOptionLabelToHtml": false,`,
48+
`"infiniteScroll": false,`,
49+
`"virtualScroll": true\n}`,
4850
].join('\n ');
4951
await expect(dialogText).toContain(strArray);
5052
});

0 commit comments

Comments
 (0)