Skip to content

Commit 0cdc99f

Browse files
committed
docs(combo-box): add virtualization example
1 parent a96fb06 commit 0cdc99f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/src/pages/components/ComboBox.svx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ Set `allowCustomValue` to `true` to let users enter custom text that isn't in th
115115

116116
<FileSource src="/framed/ComboBox/AllowCustomValue" />
117117

118+
## Virtualized (large lists)
119+
120+
Enable virtualization for large lists to improve performance. Only visible items are rendered in the DOM.
121+
122+
<FileSource src="/framed/ComboBox/VirtualizedComboBox" />
123+
118124
## Top direction
119125

120126
Set `direction` to `"top"` to make the dropdown menu appear above the input.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script>
2+
import { ComboBox } from "carbon-components-svelte";
3+
4+
// Generate large dataset
5+
const items = Array.from({ length: 5000 }, (_, i) => ({
6+
id: String(i),
7+
text: "Item " + (i + 1),
8+
}));
9+
10+
let selectedId = undefined;
11+
let value = "";
12+
</script>
13+
14+
<ComboBox
15+
titleText="Virtualized ComboBox (5,000 items)"
16+
placeholder="Filter..."
17+
helperText="Only visible items are rendered in the DOM"
18+
{items}
19+
shouldFilterItem={(item, value) =>
20+
item.text.toLowerCase().includes(value.toLowerCase())}
21+
bind:selectedId
22+
bind:value
23+
virtualize={true}
24+
/>
25+
26+
<div style="margin-top: 1rem;">
27+
{#if selectedId !== undefined}
28+
<strong>Selected:</strong>
29+
{items.find((item) => item.id === selectedId)?.text}
30+
{/if}
31+
</div>

0 commit comments

Comments
 (0)