Skip to content

EmptyState ​

Placeholder block for a collection with no records yet, or a search / filter that matched nothing. Renders an optional icon, a title, a description and one action inside a dashed-border, centered card. Presentational: it emits action and the parent decides what that means — open a create dialog, reset the filters, navigate.

bash
npm install @vuecs/elements
vue
<script setup lang="ts">
import { VCEmptyState } from '@vuecs/elements';
</script>

<template>
    <VCEmptyState
        title="No users yet"
        description="Users you create will show up here."
        action-label="Create user"
        @action="openCreateDialog"
    />
</template>
css
@import "tailwindcss";
@import "@vuecs/design";
@import "@vuecs/elements";

@custom-variant dark (&:where(.dark, .dark *));

Variants ​

variantMeaningDefault copy
empty (default)The collection has no records yetnone — pass title / description / actionLabel
noResultsA search or filter matched nothingtitle No results, description Try adjusting your search or filters., action Reset

Explicit props always win over the default copy — so pass undefined for the props you want the noResults defaults to fill. The same component covers both states of a collection page:

vue
<VCEmptyState
    :variant="filtered ? 'noResults' : 'empty'"
    :title="filtered ? undefined : 'No users yet'"
    :action-label="filtered ? undefined : 'Create user'"
    @action="filtered ? resetFilters() : openCreateDialog()"
/>

variant is also passed to the theme as a variant axis, so a theme can style the two states differently. The shipped themes use a primary action for empty and a quieter outline / light action for noResults.

Translating the default copy ​

The noResults strings are behavioral defaults under the emptyState key — set them globally, statically or as refs that follow the active locale:

ts
app.use(vuecs, {
    defaults: {
        emptyState: {
            noResultsTitle: 'Keine Ergebnisse',
            noResultsDescription: 'Passe die Suche oder die Filter an.',
            noResultsActionLabel: 'Zurücksetzen',
        },
    },
});

Action ​

The built-in action is a <button type="button"> that emits action. It renders only when actionLabel is set (or variant="noResults" supplies one). To render something else — a router link, a dropdown — use the #action slot. It receives the theme class and an action callback that emits the event:

vue
<VCEmptyState title="No projects" @action="track('empty-cta')">
    <template #action="{ class: actionClass, action }">
        <RouterLink :class="actionClass" to="/projects/new" @click="action">
            Start a project
        </RouterLink>
    </template>
</VCEmptyState>

Icon ​

icon takes an Iconify name (e.g. lucide:inbox) and renders through <VCIcon> when @vuecs/icon is installed; otherwise it is skipped. The rendered icon is aria-hidden. The #icon slot replaces it with arbitrary content.

API ​

Props ​

PropTypeDefaultDescription
titlestring—Heading text. noResults falls back to noResultsTitle.
descriptionstring—Body text. Replaced by the default slot. noResults falls back to noResultsDescription.
actionLabelstring—Label of the built-in action button. noResults falls back to noResultsActionLabel.
variant'empty' | 'noResults''empty'Which state is shown; also a theme variant.
iconstring—Iconify name for the leading icon.
asstring | Component'div'Root element.
themeClassPartial<EmptyStateThemeClasses>—Per-instance class overrides.
themeVariantVariantValues—Per-instance variant values.

Events ​

EventPayloadDescription
action—The built-in button was clicked, or the #action slot called action().

Slots ​

SlotPropsDescription
default—Replaces the description.
icon{ class }Replaces the icon prop.
title—Replaces the title prop.
action{ class, action }Replaces the built-in button. Call action() to emit the action event.

Theme keys ​

emptyState — root, icon, title, description, action. Variant axis: variant (empty / noResults).

Behavioral defaults ​

emptyState — noResultsTitle, noResultsDescription, noResultsActionLabel.

The element has no live-region role — it is static content. If it replaces results in response to typing, announce the change with your own live region.

Released under the Apache 2.0 License.