feat: migrate ListBox with virtual collection and accessible parts
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
const firstNames = [
|
||||
"Emma",
|
||||
"Liam",
|
||||
"Olivia",
|
||||
"Noah",
|
||||
"Ava",
|
||||
"James",
|
||||
"Sophia",
|
||||
"Oliver",
|
||||
"Isabella",
|
||||
"Lucas",
|
||||
"Mia",
|
||||
"Ethan",
|
||||
"Charlotte",
|
||||
"Mason",
|
||||
"Amelia",
|
||||
"Logan",
|
||||
"Harper",
|
||||
"Alexander",
|
||||
"Ella",
|
||||
"Benjamin",
|
||||
];
|
||||
const lastNames = [
|
||||
"Smith",
|
||||
"Johnson",
|
||||
"Williams",
|
||||
"Brown",
|
||||
"Jones",
|
||||
"Garcia",
|
||||
"Miller",
|
||||
"Davis",
|
||||
"Rodriguez",
|
||||
"Martinez",
|
||||
"Anderson",
|
||||
"Taylor",
|
||||
"Thomas",
|
||||
"Jackson",
|
||||
"White",
|
||||
"Harris",
|
||||
"Clark",
|
||||
"Lewis",
|
||||
"Robinson",
|
||||
"Walker",
|
||||
];
|
||||
const users = Array.from({ length: 1000 }, (_, index) => {
|
||||
const first = firstNames[index % firstNames.length];
|
||||
const last =
|
||||
lastNames[Math.floor(index / firstNames.length) % lastNames.length];
|
||||
return {
|
||||
id: index + 1,
|
||||
name: `${first} ${last}`,
|
||||
textValue: `${first} ${last}`,
|
||||
email: `${first.toLowerCase()}.${last.toLowerCase()}@acme.com`,
|
||||
};
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<ListBox
|
||||
:items="users"
|
||||
virtualized
|
||||
:row-height="50"
|
||||
aria-label="包含 1000 项的虚拟化列表"
|
||||
class="h-[400px] w-[300px] overflow-y-auto"
|
||||
v-slot="{ item }"
|
||||
>
|
||||
<ListBoxItem :id="item.id" :text-value="item.name" class="h-full">
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ item.name }}</Label>
|
||||
<Description>{{ item.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</template>
|
||||
Reference in New Issue
Block a user