List
Arrange similar content in rows using HuiListItem. Add a header and footer to the whole list, and a title and additional information to each item.
Import
import { HuiList, HuiListItem } from '@nscode/handy-ui'
Basic usage
Place HuiListItem components inside HuiList, with each item's content in its default slot. Items receive a subtle background on hover.
<script setup lang="ts">
import { HuiList, HuiListItem } from '@nscode/handy-ui'
</script>
<template>
<HuiList>
<HuiListItem>Write the weekly report</HuiListItem>
<HuiListItem>Review the order page design</HuiListItem>
<HuiListItem>Reply to customer emails</HuiListItem>
</HuiList>
</template>
Border
border adds an outer border and rounded corners. The first list below has no border (the default), and the second enables border:
<template>
<HuiSpace direction="vertical" fill>
<HuiList header="Without a border">
<HuiListItem>Write the weekly report</HuiListItem>
<HuiListItem>Review the order page design</HuiListItem>
</HuiList>
<HuiList header="border" border>
<HuiListItem>Write the weekly report</HuiListItem>
<HuiListItem>Review the order page design</HuiListItem>
</HuiList>
</HuiSpace>
</template>
Header and footer
Pass text through header and footer to display it at the top and bottom of the list.
<template>
<HuiList header="Tasks" footer="3 items" border>
<HuiListItem>Write the weekly report</HuiListItem>
<HuiListItem>Review the order page design</HuiListItem>
<HuiListItem>Reply to customer emails</HuiListItem>
</HuiList>
</template>
Use the header and footer slots for buttons or other content. A slot replaces the corresponding prop.
<script setup lang="ts">
import { HuiList, HuiListItem, HuiButton } from '@nscode/handy-ui'
</script>
<template>
<HuiList border>
<template #header>
<div style="display: flex; justify-content: space-between; align-items: center">
<span>Tasks</span>
<HuiButton size="small" type="primary" icon="plus">Add</HuiButton>
</div>
</template>
<HuiListItem>Write the weekly report</HuiListItem>
<HuiListItem>Review the order page design</HuiListItem>
<template #footer>
<HuiButton type="primary" variant="link" href="https://example.com" target="_blank">
View all
</HuiButton>
</template>
</HuiList>
</template>
Item titles and additional information
HuiListItem also accepts header and footer: the title appears above the content, and additional information appears below it in smaller text. Both can be replaced with slots.
<script setup lang="ts">
import { HuiButton, HuiList, HuiListItem, HuiSpace, HuiTag } from '@nscode/handy-ui'
</script>
<template>
<HuiList border>
<HuiListItem header="Version 1.2.0 released" footer="2026-03-01">
Added fixed table columns and fixed pagination page numbers.
</HuiListItem>
<HuiListItem footer="2026-02-15">
<template #header>
<HuiSpace :size="8">
<strong>Version 1.1.0 released</strong>
<HuiTag size="small" type="success">Stable</HuiTag>
</HuiSpace>
</template>
Added the timeline component.
</HuiListItem>
<HuiListItem header="Version 1.0.0 released">
First stable release.
<template #footer>
<HuiSpace :size="8">
<span>2026-01-10</span>
<HuiButton size="small" variant="link" type="primary">View release notes</HuiButton>
</HuiSpace>
</template>
</HuiListItem>
</HuiList>
</template>
Sizes
size accepts large, default, or small, affecting the padding and font size of the header, footer, and items. Padding is 20, 16, and 12px respectively. Both large and default text use 14px (large header titles use 16px); small uses 12px. When omitted, size follows ConfigProvider, falling back to default.
<template>
<HuiSpace direction="vertical" fill>
<HuiList size="large" header="large" footer="2 items" border>
<HuiListItem header="Write the weekly report" footer="By 18:00 today"
>Send to the manager before end of day Friday</HuiListItem
>
<HuiListItem>Review the order page design</HuiListItem>
</HuiList>
<HuiList header="default" footer="2 items" border>
<HuiListItem header="Write the weekly report" footer="By 18:00 today"
>Send to the manager before end of day Friday</HuiListItem
>
<HuiListItem>Review the order page design</HuiListItem>
</HuiList>
<HuiList size="small" header="small" footer="2 items" border>
<HuiListItem header="Write the weekly report" footer="By 18:00 today"
>Send to the manager before end of day Friday</HuiListItem
>
<HuiListItem>Review the order page design</HuiListItem>
</HuiList>
</HuiSpace>
</template>
Loading
When loading is true, a translucent overlay and loading indicator cover the items and prevent item clicks. The header and footer remain available. While loading with no items yet, the empty state is hidden; it appears only if there is still no data after loading finishes. Toggle loading directly or click Refresh to simulate a 1.5-second request:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiList, HuiListItem, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
const loading = ref(true)
const batch = ref(1)
const messages = [
'Zhang Wei commented on your article',
'Wang Fang assigned you a task',
'System maintenance starts tonight at 23:00'
]
const refresh = () => {
loading.value = true
window.setTimeout(() => {
batch.value++
loading.value = false
}, 1500)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace wrap>
<HuiSwitch v-model="loading" active-text="loading" />
<HuiButton icon="refresh" :loading="loading" @click="refresh">Refresh</HuiButton>
</HuiSpace>
<HuiList :loading="loading" header="Latest messages" :footer="`Refresh ${batch}`" border>
<HuiListItem v-for="text in messages" :key="text">{{ text }}</HuiListItem>
</HuiList>
</HuiSpace>
</template>
Clicking items
HuiListItem does not declare a click event. Add @click directly; it falls through to the root element. This example selects the clicked item and applies a custom class for its selected background:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiList, HuiListItem } from '@nscode/handy-ui'
const contacts = [
{ id: 1, name: '张伟', dept: '研发部' },
{ id: 2, name: '王芳', dept: '市场部' },
{ id: 3, name: '李娜', dept: '财务部' }
]
const activeId = ref(1)
</script>
<template>
<HuiList class="contacts" border>
<HuiListItem
v-for="item in contacts"
:key="item.id"
:header="item.name"
:class="{ 'is-active': item.id === activeId }"
style="cursor: pointer"
@click="activeId = item.id"
>
{{ item.dept }}
</HuiListItem>
<template #footer>Selected: {{ contacts.find((c) => c.id === activeId)?.name }}</template>
</HuiList>
</template>
<style scoped>
.contacts .is-active,
.contacts .is-active:hover {
background-color: var(--hui-color-primary-bg);
}
</style>
Rendering an array
List items are usually generated with v-for. The component has no built-in empty state; provide a message in its default slot when the array is empty, for example with HuiEmpty. Clearing and deleting both require confirmation of the target and scope. Canceling, closing, or pressing Esc preserves the data. Adding, replacing, or editing items, changing read-only state, or unmounting the example while confirmation is pending invalidates it. The read-only switch protects this example's delete actions; it is not an HuiList prop.
<script setup lang="ts">
import { onUnmounted, ref, watch } from 'vue'
import {
HuiButton,
HuiEmpty,
HuiList,
HuiListItem,
HuiMessageBox,
HuiSpace,
HuiSwitch
} from '@nscode/handy-ui'
interface Todo {
id: number
title: string
desc: string
}
const candidates = ['整理会议纪要', '更新项目排期', '准备季度汇报', '跟进合同回款']
const items = ref<Todo[]>([
{
id: 1,
title: 'Write the weekly report',
desc: 'Send to the manager before end of day Friday'
},
{ id: 2, title: 'Review the order page design', desc: 'Wednesday 2pm, room 3' }
])
const readonly = ref(false)
const pending = ref(false)
let alive = true
let revision = 0
watch([items, readonly], () => revision++, { deep: true, flush: 'sync' })
onUnmounted(() => {
alive = false
revision++
})
let nextId = 3
const add = () => {
const title = candidates[(nextId - 3) % candidates.length]
items.value.push({ id: nextId++, title, desc: 'Newly added task' })
}
const requestDelete = async (id?: number) => {
if (!alive || readonly.value || pending.value || !items.value.length) return
const target = items.value
const row = id === undefined ? undefined : target.find((item) => item.id === id)
if (id !== undefined && !row) return
const request = revision
pending.value = true
try {
await HuiMessageBox.confirm({
title: row ? 'Delete task' : 'Clear tasks',
message: row
? `Delete task “${row.title}” and its description? Only this item is affected; other tasks will remain.`
: `Clear all ${target.length} tasks and their descriptions from this list? Other data will remain.`,
type: 'warning'
})
if (!alive || readonly.value || request !== revision || items.value !== target) return
items.value = row ? target.filter((item) => item !== row) : []
} catch {
// Canceling, closing, or pressing Esc leaves the list unchanged.
} finally {
if (alive) pending.value = false
}
}
const remove = (id: number) => requestDelete(id)
const clear = () => requestDelete()
</script>
<template>
<HuiList border :footer="`${items.length} items`">
<template #header>
<HuiSpace wrap>
<HuiButton size="small" type="primary" icon="plus" @click="add">Add</HuiButton>
<HuiButton size="small" :disabled="readonly || pending || items.length === 0" @click="clear"
>Clear</HuiButton
>
<HuiSwitch v-model="readonly" active-text="Read-only delete protection" />
</HuiSpace>
</template>
<HuiListItem v-for="item in items" :key="item.id" :header="item.title">
{{ item.desc }}
<template #footer>
<HuiButton
size="small"
variant="link"
type="danger"
:disabled="readonly || pending"
@click="remove(item.id)"
>
Delete
</HuiButton>
</template>
</HuiListItem>
<HuiEmpty v-if="items.length === 0" description="No tasks" />
</HuiList>
</template>
Metadata, Responsive Grids and Nested Replies
Avatar, description, side content and actions share a consistent layout. This example switches every size, grid mode, dividers, hover backgrounds and built-in or custom empty content. Actions report their result on the page. Previewing an empty state preserves the source data.
grid.column accepts a number or responsive breakpoint values; gutter uses pixels. Headers and footers remain full-width. Grid mode ignores row dividers and hover backgrounds. Nested lists use their own settings rather than inheriting an outer list's explicit choices. The gap can also be overridden with the CSS variable --hui-list-gutter, set on the list itself or any ancestor; it takes precedence over gutter.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiAvatar, HuiButton, HuiInput, HuiList, HuiListItem, HuiSpace } from '@nscode/handy-ui'
import type { ListGrid, ListSize } from '@nscode/handy-ui'
const size = ref<ListSize>('default')
const sizes: ListSize[] = ['small', 'default', 'large']
const gridEnabled = ref(false)
const showDivider = ref(true)
const hoverable = ref(true)
const empty = ref(false)
const customEmpty = ref(false)
const note = ref('Unsaved note')
const status = ref('No action yet')
const grid = computed<ListGrid | undefined>(() =>
gridEnabled.value ? { column: { xs: 1, md: 2, xl: 3 }, gutter: 16 } : undefined
)
const avatar =
'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"%3E%3Ctext x="20" y="28" text-anchor="middle" font-size="28"%3EA%3C/text%3E%3C/svg%3E'
const members = [
{ id: 1, name: 'Alex', description: 'Engineering · Approval owner', count: 3 },
{ id: 2, name: 'Blair', description: 'Marketing · Project contact', count: 2 },
{ id: 3, name: 'Casey', description: 'Finance · Reviewer', count: 1 }
]
</script>
<template>
<HuiSpace class="list-features-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiButton
v-for="value in sizes"
:key="value"
:type="size === value ? 'primary' : 'default'"
@click="size = value"
>{{ value }}</HuiButton
>
<HuiButton @click="gridEnabled = !gridEnabled">{{
gridEnabled ? 'Show rows' : 'Show grid'
}}</HuiButton>
<HuiButton @click="showDivider = !showDivider">Dividers: {{ showDivider }}</HuiButton>
<HuiButton @click="hoverable = !hoverable">Hover: {{ hoverable }}</HuiButton>
<HuiButton @click="empty = !empty">{{ empty ? 'Show data' : 'Preview empty' }}</HuiButton>
<HuiButton @click="customEmpty = !customEmpty">Custom empty: {{ customEmpty }}</HuiButton>
</HuiSpace>
<p role="status">{{ status }}</p>
<HuiList
:size="size"
:grid="grid"
:show-divider="showDivider"
:hoverable="hoverable"
header="Project members"
footer="Data and the note are retained when switching layout or previewing empty content."
empty-text="No project members"
border
>
<HuiListItem
v-for="member in empty ? [] : members"
:key="member.id"
:header="member.name"
:description="member.description"
:avatar="member.id === 1 ? avatar : undefined"
>
<template v-if="member.id !== 1" #avatar
><HuiAvatar>{{ member.name.slice(0, 1) }}</HuiAvatar></template
>
<span>{{ member.count }} pending items</span>
<HuiInput v-if="member.id === 1" v-model="note" aria-label="Alex's note" />
<template #extra><span>Available</span></template>
<template #actions>
<HuiButton size="small" variant="link" @click="status = `Viewed ${member.name}`"
>View</HuiButton
>
<HuiButton size="small" variant="link" @click="status = `Contacted ${member.name}`"
>Contact</HuiButton
>
</template>
</HuiListItem>
<template v-if="customEmpty" #empty
><p>No members assigned. Complete the project setup first.</p></template
>
</HuiList>
<HuiList
header="Comments and replies"
size="small"
:show-divider="false"
:hoverable="false"
border
>
<HuiListItem header="Alex" description="Outer list: dividers and hover disabled">
Please add a review.
<HuiList size="default">
<HuiListItem header="Blair" description="Inner list uses its own defaults"
>Reviewed; all documents are present.</HuiListItem
>
<HuiListItem header="Casey" description="Inner list uses its own defaults"
>Approved.</HuiListItem
>
</HuiList>
</HuiListItem>
</HuiList>
</HuiSpace>
</template>
HuiList Props
| Prop | Type | Default | Description |
|---|---|---|---|
| header | string | - | Header text; hidden when the header slot is provided |
| footer | string | - | Footer text; hidden when the footer slot is provided |
| loading | boolean | false | Whether to show the loading overlay |
| size | 'large' | 'default' | 'small' | - | Size of header, footer, and item padding and text; follows ConfigProvider when omitted, falling back to 'default' |
| border | boolean | false | Whether to show an outer border |
| showDivider | boolean | true | Display dividers between items; ignored in grid mode |
| hoverable | boolean | true | Show item backgrounds on hover; ignored in grid mode |
| emptyText | string | Localized | Built-in empty description; an explicit empty string hides it |
| grid | ListGrid | — | Columns and gaps in the content area; header and footer remain full-width |
HuiListItem Props
| Prop | Type | Default | Description |
|---|---|---|---|
| header | string | - | Item title above its content; hidden when the header slot is provided |
| footer | string | - | Additional information below item content; hidden when the footer slot is provided |
| avatar | string | — | Avatar URL, overridden by the avatar slot; default sizes are 32/40/48px for small/default/large |
| description | string | — | Description below the title, overridden by the description slot |
HuiList Slots
| Slot | Scope | Description |
|---|---|---|
| default | - | List content containing HuiListItem components |
| header | - | List header |
| footer | - | List footer |
| empty | — | Full-width empty content, overriding emptyText even when the slot is explicitly empty |
HuiListItem Slots
| Slot | Scope | Description |
|---|---|---|
| default | - | Item content |
| header | - | Item title |
| footer | - | Additional item information |
| avatar | — | Avatar or icon on the left |
| description | — | Description below the title |
| extra | — | Content on the right |
| actions | — | Actions below the main content; separators are added between actions |
Types
import type {
ListProps,
ListItemProps,
ListSize,
ListGrid,
ListSlots,
ListItemSlots
} from '@nscode/handy-ui'
import type { VNode } from 'vue'
type ListSize = 'large' | 'default' | 'small'
interface ListProps {
header?: string
footer?: string
loading?: boolean
size?: ListSize
border?: boolean
showDivider?: boolean
hoverable?: boolean
emptyText?: string
grid?: ListGrid
}
interface ListItemProps {
header?: string
footer?: string
avatar?: string
description?: string
}
interface ListSlots {
default?: () => VNode[]
header?: () => VNode[]
footer?: () => VNode[]
empty?: () => VNode[]
}
interface ListItemSlots {
default?: () => VNode[]
header?: () => VNode[]
footer?: () => VNode[]
avatar?: () => VNode[]
description?: () => VNode[]
extra?: () => VNode[]
actions?: () => VNode[]
}