OverflowList
Keep a row of tags or members visible and move items that do not fit behind a count indicator.
Import
import { HuiOverflowList } from '@nscode/handy-ui'
import type { OverflowListProps } from '@nscode/handy-ui'
Resizable tag row
Drag the lower right corner to resize. The change event reports changes in hidden count; no indicator appears when everything fits.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiOverflowList, HuiSpace, HuiTag } from '@nscode/handy-ui'
const items = ['Planning', 'Design', 'Development', 'Integration', 'Deployment', 'Maintenance']
const hidden = ref(0)
</script>
<template>
<HuiSpace direction="vertical" fill>
<div class="resizable">
<div style="display: flex; align-items: center; gap: 8px; min-width: 0">
<strong style="flex: none">Tags</strong>
<HuiOverflowList :items="items" @change="hidden = $event">
<template #item="{ item }"
><HuiTag>{{ item }}</HuiTag></template
>
</HuiOverflowList>
</div>
</div>
<span>{{ hidden }} hidden; use Enter, Space and Escape on the indicator.</span>
</HuiSpace>
</template>
<style scoped>
.resizable {
flex: none;
width: 320px;
max-width: 100%;
min-width: 120px;
padding: 12px;
resize: horizontal;
overflow: auto;
border: 1px solid var(--hui-border-color);
}
</style>
Collapse direction and original indexes
With from=end the first items remain visible and the indicator comes last. With from=start the last items remain visible and the indicator comes first. Slot indexes always refer to the original array. Supply stable unique keys to preserve component state during reordering.
<script setup lang="ts">
import { HuiOverflowList, HuiSpace, HuiTag } from '@nscode/handy-ui'
const items = [
{ id: 'a', name: 'Projects' },
{ id: 'b', name: 'Assignment' },
{ id: 'c', name: 'Tracking' },
{ id: 'd', name: 'Archive' }
]
const keyOf = (item: { id: string }) => item.id
</script>
<template>
<HuiSpace direction="vertical" fill>
<div style="flex: none; width: 240px; max-width: 100%">
<p>end, field key</p>
<HuiOverflowList :items="items" item-key="id" from="end">
<template #item="{ item, index }"
><HuiTag>{{ index }} · {{ item.name }}</HuiTag></template
>
</HuiOverflowList>
</div>
<div style="flex: none; width: 240px; max-width: 100%">
<p>start, function key</p>
<HuiOverflowList :items="items" :item-key="keyOf" from="start">
<template #item="{ item, index }"
><HuiTag>{{ index }} · {{ item.name }}</HuiTag></template
>
</HuiOverflowList>
</div>
</HuiSpace>
</template>
Minimum count and spacing
The minimum count takes priority over available width: those items remain rendered, while content beyond the root is clipped. Provide enough external width when every retained item must be visible. Numbers and numeric strings are pixels. A single CSS length such as rem, em or calc(...) is also supported.
<script setup lang="ts">
import { HuiOverflowList, HuiSpace, HuiTag } from '@nscode/handy-ui'
const items = ['Records', 'Scheduling', 'Execution', 'Analytics']
const gaps = [0, 8, '1rem', 'calc(1rem + 4px)']
</script>
<template>
<HuiSpace direction="vertical" fill>
<div style="flex: none; width: 140px; padding-bottom: 8px; overflow: auto">
<p>min=2, excess content clipped</p>
<HuiOverflowList :items="items" :min="2">
<template #item="{ item }"
><HuiTag>{{ item }}</HuiTag></template
>
</HuiOverflowList>
</div>
<div v-for="gap in gaps" :key="String(gap)" style="flex: none; width: 260px; max-width: 100%">
<p>gap={{ gap }}</p>
<HuiOverflowList :items="items" :gap="gap">
<template #item="{ item }"
><HuiTag>{{ item }}</HuiTag></template
>
</HuiOverflowList>
</div>
</HuiSpace>
</template>
Triggers and custom slots
Hover opens on pointer hover; click toggles on click. Both support Enter or Space to open and Escape to close. The none setting displays a static count without button semantics or a popover. Keep the overflow slot presentational; do not nest interactive buttons or links in it. The popover slot replaces the hidden-item list.
<script setup lang="ts">
import { HuiOverflowList, HuiSpace, HuiTag } from '@nscode/handy-ui'
import type { OverflowListTrigger } from '@nscode/handy-ui'
const triggers: OverflowListTrigger[] = ['hover', 'click', 'none']
const items = ['System', 'Permissions', 'Audit', 'Monitoring', 'Notifications']
</script>
<template>
<HuiSpace direction="vertical" fill>
<div
v-for="trigger in triggers"
:key="trigger"
style="flex: none; width: 240px; max-width: 100%"
>
<p>{{ trigger }}</p>
<HuiOverflowList :items="items" :overflow-trigger="trigger">
<template #item="{ item }"
><HuiTag>{{ item }}</HuiTag></template
>
</HuiOverflowList>
</div>
<div style="flex: none; width: 240px; max-width: 100%">
<p>Custom indicator and panel</p>
<HuiOverflowList :items="items" overflow-trigger="click">
<template #item="{ item }"
><HuiTag type="success">{{ item }}</HuiTag></template
>
<template #overflow="{ count }"
><HuiTag type="warning">{{ count }} others</HuiTag></template
>
<template #popover="{ items: hidden }">
<HuiSpace direction="vertical"
><strong>Hidden features</strong><span>{{ hidden.join(', ') }}</span></HuiSpace
>
</template>
</HuiOverflowList>
</div>
</HuiSpace>
</template>
Table cells and changing data
The container and each measuring item are observed independently. Changes in text, images or fonts schedule a fresh measurement. Multiple notifications in a frame share one measurement batch.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiOverflowList, HuiSpace, HuiTable, HuiTag } from '@nscode/handy-ui'
import type { TableColumnConfig } from '@nscode/handy-ui'
const rows = ref([
{ id: 1, name: 'Alex', roles: ['Records', 'Planning', 'Approval', 'Export'] },
{ id: 2, name: 'Sam', roles: ['Analytics', 'Audit'] }
])
const columns: TableColumnConfig[] = [
{ prop: 'name', label: 'Name', width: 100 },
{ prop: 'roles', label: 'Permissions' }
]
const append = () =>
rows.value[0].roles.push(`Extra permission ${rows.value[0].roles.length + 1}`)
</script>
<template>
<HuiSpace direction="vertical" fill style="flex: none; max-width: 460px">
<HuiButton @click="append">Append permission to first row</HuiButton>
<HuiTable :data="rows" :columns="columns" border>
<template #roles="{ row }">
<HuiOverflowList :items="row.roles" overflow-trigger="click">
<template #item="{ item }"
><HuiTag size="small">{{ item }}</HuiTag></template
>
</HuiOverflowList>
</template>
</HuiTable>
</HuiSpace>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items | T[] | Required | Original ordered data |
| min | number | 0 | Minimum visible count, capped to item count; fractions round down |
| from | OverflowListFrom | 'end' | End or start to collapse |
| gap | number | string | 8 | Pixels for numbers or numeric strings; otherwise one CSS length |
| overflowTrigger | OverflowListTrigger | 'hover' | hover, click or none |
| itemKey | string | ((item: T, index: number) => string | number) | Original index | Stable unique key |
Events
| Event | Payload | Description |
|---|---|---|
| change | (hiddenCount: number) | Emitted when hidden count changes; 0 when all items become visible; no initial event if none are hidden |
Slots
| Slot | Props | Description |
|---|---|---|
| item | { item: T, index: number } | Original item and index; displays data directly by default |
| overflow | { items: T[], count: number } | Hidden items and count; small +N tag by default; presentational content only |
| popover | { items: T[] } | Hidden-item panel; reuses the item slot in a vertical list by default |
Methods
No public methods. Measurement follows data and size changes automatically.
Types
import type {
OverflowListProps,
OverflowListFrom,
OverflowListTrigger,
OverflowListItemSlotProps,
OverflowListOverflowSlotProps,
OverflowListPopoverSlotProps
} from '@nscode/handy-ui'
type OverflowListFrom = 'start' | 'end'
type OverflowListTrigger = 'hover' | 'click' | 'none'
interface OverflowListProps<T = unknown> {
items: T[]
min?: number
from?: OverflowListFrom
gap?: number | string
overflowTrigger?: OverflowListTrigger
itemKey?: string | ((item: T, index: number) => string | number)
}