-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/virtualization for autocomplete (#4094)
* feat: add react-window virtualization for autocomplete * fix: wrong imports and wrong sizing * fix: update pnpm lock * chore: add test cases for large dataset (1000 and 10000 items) * chore: move virtualized-listbox to listbox components folder, implement isVirtualized conditional * feat: implement dynamic listboxheight n item height, add story * chore: rename props, remove unnecessary line changes * fix: maxHeight style 256px for default, conditional usage of virtualizer * feat: migrate to tan-stack virtual. (todo: fix scroll shadow) * feat: virtualization support --------- Co-authored-by: Vincentius Roger Kuswara <[email protected]>
- Loading branch information
1 parent
f81ad5e
commit b9d5d49
Showing
16 changed files
with
717 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@nextui-org/autocomplete": patch | ||
"@nextui-org/listbox": patch | ||
"@nextui-org/theme": patch | ||
--- | ||
|
||
Virtualization support added to Listbox & Autocomplete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
apps/docs/content/components/autocomplete/virtualization-custom-item-height.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const App = `import {Autocomplete, AutocompleteItem} from "@nextui-org/react"; | ||
const generateItems = (n) => { | ||
const items = [ | ||
"Cat", | ||
"Dog", | ||
"Elephant", | ||
"Lion", | ||
"Tiger", | ||
"Giraffe", | ||
"Dolphin", | ||
"Penguin", | ||
"Zebra", | ||
"Shark", | ||
"Whale", | ||
"Otter", | ||
"Crocodile", | ||
]; | ||
const dataset = []; | ||
for (let i = 0; i < n; i++) { | ||
const item = items[i % items.length]; | ||
dataset.push({ | ||
label: \`\${item}\${i}\`, | ||
value: \`\${item.toLowerCase()}\${i}\`, | ||
description: "Sample description", | ||
}); | ||
} | ||
return dataset; | ||
}; | ||
export default function App() { | ||
const items = generateItems(1000); | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<Autocomplete | ||
isVirtualized | ||
label="Search from 1000 items" | ||
className="max-w-xs" | ||
defaultItems={items} | ||
placeholder="Search..." | ||
maxListboxHeight={400} | ||
itemHeight={40} | ||
> | ||
{(item) => ( | ||
<AutocompleteItem key={item.value}> | ||
{item.label} | ||
</AutocompleteItem> | ||
)} | ||
</Autocomplete> | ||
</div> | ||
); | ||
}`; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
export default { | ||
...react, | ||
}; |
64 changes: 64 additions & 0 deletions
64
apps/docs/content/components/autocomplete/virtualization-max-listbox-height.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const App = `import {Autocomplete, AutocompleteItem} from "@nextui-org/react"; | ||
const generateItems = (n) => { | ||
const items = [ | ||
"Cat", | ||
"Dog", | ||
"Elephant", | ||
"Lion", | ||
"Tiger", | ||
"Giraffe", | ||
"Dolphin", | ||
"Penguin", | ||
"Zebra", | ||
"Shark", | ||
"Whale", | ||
"Otter", | ||
"Crocodile", | ||
]; | ||
const dataset = []; | ||
for (let i = 0; i < n; i++) { | ||
const item = items[i % items.length]; | ||
dataset.push({ | ||
label: \`\${item}\${i}\`, | ||
value: \`\${item.toLowerCase()}\${i}\`, | ||
description: "Sample description", | ||
}); | ||
} | ||
return dataset; | ||
}; | ||
export default function App() { | ||
const items = generateItems(1000); | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<Autocomplete | ||
isVirtualized | ||
label="Search from 1000 items" | ||
className="max-w-xs" | ||
defaultItems={items} | ||
placeholder="Search..." | ||
maxListboxHeight={400} | ||
> | ||
{(item) => ( | ||
<AutocompleteItem key={item.value}> | ||
{item.label} | ||
</AutocompleteItem> | ||
)} | ||
</Autocomplete> | ||
</div> | ||
); | ||
}`; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
export default { | ||
...react, | ||
}; |
63 changes: 63 additions & 0 deletions
63
apps/docs/content/components/autocomplete/virtualization-ten-thousand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const App = `import {Autocomplete, AutocompleteItem} from "@nextui-org/react"; | ||
const generateItems = (n) => { | ||
const items = [ | ||
"Cat", | ||
"Dog", | ||
"Elephant", | ||
"Lion", | ||
"Tiger", | ||
"Giraffe", | ||
"Dolphin", | ||
"Penguin", | ||
"Zebra", | ||
"Shark", | ||
"Whale", | ||
"Otter", | ||
"Crocodile", | ||
]; | ||
const dataset = []; | ||
for (let i = 0; i < n; i++) { | ||
const item = items[i % items.length]; | ||
dataset.push({ | ||
label: \`\${item}\${i}\`, | ||
value: \`\${item.toLowerCase()}\${i}\`, | ||
description: "Sample description", | ||
}); | ||
} | ||
return dataset; | ||
}; | ||
export default function App() { | ||
const items = generateItems(10000); | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<Autocomplete | ||
isVirtualized | ||
label="Search from 1000 items" | ||
className="max-w-xs" | ||
defaultItems={items} | ||
placeholder="Search..." | ||
> | ||
{(item) => ( | ||
<AutocompleteItem key={item.value}> | ||
{item.label} | ||
</AutocompleteItem> | ||
)} | ||
</Autocomplete> | ||
</div> | ||
); | ||
}`; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
export default { | ||
...react, | ||
}; |
Oops, something went wrong.