ContentUnavailableView
is a UI component designed to present a view when the content in your app is unavailable. It typically shows a title, an optional description, and an action area, making it clear to users that content is missing or not yet available. This component can be used in places like lists, where no data is available to show to the user.
You can pass one of two structures of properties to the ContentUnavailableView
component:
String-based Props:
title
(string): The main title to display, typically describing the content that is unavailable.systemImage
(string): A system icon to visually represent the unavailable content. This is used to enhance the UI and provide an intuitive, recognizable symbol.description
(string, optional): A brief text description of the unavailable content. This is optional and can be omitted if not needed.VirtualNode-based Props:
label
(VirtualNode): A virtual node, typically a Text
or any other UI component, that will serve as the label describing the unavailable content.description
(VirtualNode | null, optional): A virtual node, usually a Text
component, that provides more detailed information about the unavailable content. If you don't need a description, this can be set to null
.actions
(Array of VirtualNode | null, optional): An optional list of action buttons or links to display. These actions can be buttons, links, or other components, and they can be null
if no actions are needed.In this example, ContentUnavailableView
is used to show a message with an icon when the list of documents is empty. If the documents
array is empty, the view will show the title "No documents" and a system icon "tray.fill"
.
In this example, the ContentUnavailableView
is passed virtual nodes for the label and description. It also includes an action button to refresh the list of documents.
title
and systemImage
: Provide a simple, static way to show unavailable content with a string title and system icon.label
and description
: Allow you to customize the label and description with full control, using VirtualNode
components.actions
: Optional actions can be added to guide users, like buttons or links, that perform actions like refreshing content or redirecting users to another screen.This component is ideal for UIs where content might be temporarily unavailable and you want to display a consistent and clear message to users.