Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Empty States Table Block for React

A contact book table with two empty states you reach by doing something: searching for text that is not there, and removing every contact after a confirm, then adding the samples back, all at one fixed height.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Design the empty table, not just the full one, with this contact book for React with Base UI. One framed panel with a plus mark on each corner holds an inset card, a Frame, with a search field and a Remove all button over a native table of six contacts in a region of fixed height. Searching for something that is not there fills the region under the table's head with the no-results Empty state: it names the query, and its Clear search button puts focus back in the field. Remove all opens an Alert Dialog that says how many contacts go, and confirming it shows the first-run state, whose one primary is a Shine Button, "Add sample contacts": it brings back the six typed contacts and focuses the first one's email. Both states take exactly the space of the rows, so the card never changes height, and a status line under the table says what just happened. On a phone the company and phone fold under the name. It's built from Empty, Frame, Alert Dialog, Shine Button, Input Group, Button and Guides, with a CSS entrance only. For address books, directories and any list a visitor can empty or search to nothing.

FAQ

How do I fill it with my own contacts?

Edit SAMPLE: each contact has an id, a name, an email, a company and a phone. The count in the foot, the number in the confirm dialog and the search results are all worked out from the list in state, so nothing is typed twice. To search more fields, add them to matches. The search ignores case and accents, so "valtys" finds "Valtysdottir".

What are the two empty states, and when do they show?

The no-results state shows when the search matches nothing: its title names the query, its text says to check the spelling and its one button clears the search and focuses the field. The first-run state shows when there are no contacts at all, which here you reach with Remove all: its one button, Add sample contacts, is the block's only primary. They are two different messages on purpose: one says the search failed, the other says there is nothing to search.

What stays local, and how do I wire real removal?

Everything happens in the page: the contacts are a useState list, Remove all empties it and Add sample contacts refills it from SAMPLE; nothing is stored or sent. For real data, send the delete from the dialog's action handler, wait for it, then set the list from the response, and put your own sample or import step behind the first-run button. Keep the confirm: a bulk delete should ask.

Where does focus go in each case?

Clear search, and Escape in the field, put focus in the search field. Confirming Remove all moves it, about a third of a second later so the dialog has finished closing, to the Add sample contacts button that replaced the rows. Adding the samples moves it to the first contact's email, so the keyboard lands on the new content. Cancelling the dialog, or pressing Escape, returns focus to the Remove all button, which is how the dialog behaves in every library.

Does the card change height when a state changes?

No. The table sits in a region of fixed height with a head that stays in place, and each empty state is a block that fills the rest of that region under the head, so rows, no-results and first-run all occupy the same space. The status line under the region reserves two lines on a phone.

How does it look on a phone?

The field and Remove all share a row that wraps, and the table keeps Name and Email, with the company and phone folded under the name. Long emails wrap rather than being cut, and the region scrolls inside the card if the rows are taller than it.

  • Pro

    A library catalogue table with a search field and an availability menu: typing keeps the titles whose name or author holds the words and marks them, the foot says how many match, and an empty state under the head clears the search.

  • Pro

    Chip Filters Table

    Sort and search

    A bug table beside a rail of chip filters for priority and status: chips in a group are or, the groups are and, every chip counts what it would show, and an empty state clears them all.

  • Pro

    Sortable Members Table

    Sort and search

    A members table whose column heads are buttons: press one to sort, again to reverse, a third time for the original order, with aria-sort on the active head, ties settled by name and a spoken line for each result.

  • Pro

    Paginated Orders Table

    Columns and paging

    An orders table of 24 rows that pages: a rows-per-page menu, the numbered pagination, a polite line saying which orders are on screen, and every page drawn once more unseen so the pager never moves.

  • Pro

    A customer segments table ordered by a two-rule sort builder: pick a column and a direction for the first rule and for the tie-break, see the order as a 1 and a 2 on the heads, and Reset to start again.

  • Pro

    A ticket queue where a switch raises any ticket due within two days by one level, shown as drawn bars, a word and a raised-from note, and the Priority head sorts by that effective rank.