shadcn.io is not affiliated with official shadcn/ui
Filter Chips Blog Block for React
A coffee journal's archive with a ruled band of category chips and their counts over eight post cells: choosing a chip removes the other posts, a polite line says how many show, and the wall keeps its height.
Installation
Overview
A filterable post wall for React with Base UI, written for Gooseneck, a coffee-brewing journal. A start-aligned header sits over a ruled band holding one chip per category with its count (All 8, Brewing 3, Roasting 2, Gear 2, Origin 1) and a polite status line, and under the band eight post cells share their hairlines from rail to rail, four across on a desktop and two on a tablet. Choosing a chip removes the other categories' posts instead of dimming them, and the line says "Showing 3 of 8 posts"; an unseen copy of the full wall sits in the same cell, so the block keeps its height and nothing below it moves. Every category owns a drawn line pattern (rings, stripes, dots, contours), so you can tell a category's posts apart before reading a title. Each card is one link, its title. On a phone the cards become rows with the cover as a thumbnail and the chips scroll sideways, the next one peeking at the edge. It's built from Toggle Group, Badge, Avatar and Guides, with CSS for the entrance and the hover. For editorial blogs, journals and any archive with a handful of topics.
FAQ
How do I add my own posts and categories?
Edit POSTS at the top of the file: a title, a one-line dek, an author, a category, a date as an ISO string, minutes of reading and an href. The chips, their counts and the status line are all derived from the array. To add a category, add its name to the Category type and to CATEGORIES, and give it a pattern in PATTERNS. Eight posts fill two rows of four; any count works, because each cell draws its own hairlines.
Why does the block not change height when I filter?
The wall is drawn twice in one grid cell. The visible copy holds the posts that match; an unseen copy of all eight (hidden from assistive technology and the keyboard) sets the height, so the cell is always as tall as the full wall. Choosing a chip only removes cards from the visible copy. The cards left show from the first cell, and the polite status line, the only text that moves, says "Showing 3 of 8 posts" so a screen reader hears what changed. A layout check will report the cards moving; that is the filter working.
How do the covers work, and can I use photos?
Each cover is the line pattern its post's category owns, built from path strings at the top of the file in two weights of the foreground colour, so every Roasting post has the same diagonal stripes and the filter means something. All colours are your theme's tokens. To use photos, put an img with size-full object-cover in PostCover; the frame keeps its aspect, ring and radius, and a phone shows it as a thumbnail.
How does it work with a keyboard and a screen reader?
The chips are one single-choice group named "Filter posts by category": Tab reaches the group once, the arrow keys move between chips, Space or Enter chooses the one in focus, and the pressed chip is the one filtered. Each card is one link, its title, whose focus ring is drawn around the whole card. The status line is a polite live region.
How does it fit on a phone?
The chips sit in a row that scrolls sideways, with the next chip peeking so the row reads as scrollable, and the status line goes under it. The cards become rows: the category and title at the start with the cover as a small thumbnail at the end, then the byline across the full width; the dek is left out on a phone to keep eight posts within about two and a half screens. Nothing scrolls the page sideways at 320 pixels.
Related
- Pro
Search Grid Blog
Card gridsA developer-tools blog behind a search field: a slash shortcut focuses it, typing keeps the posts whose title or summary holds the words and marks them, and six cells draw tiny tool windows as covers.
- Pro
Tag Cloud Blog
Topics and indexesA foraging blog's tag cloud: fourteen tags in five sizes derived from their post counts, each a toggle that lists its three latest posts in a fixed-height panel beside the cloud.
- Pro
Categories Blog
Topics and indexesA houseplant magazine's category index: seven cells on shared hairlines, each a link with an icon ring, a scope, the latest post, a post count and a bar for its share, derived from the list of posts.
- Pro
Cards Grid Blog
Card gridsThe six latest posts of an engineering blog as cards on shared hairlines: drawn greyscale covers, a category, the title as the card's one link, a one-line dek and a byline with the date and reading time.
- Pro
Tabs Layout Blog
Post listsA film-criticism reading list with three underline tabs, Latest, Popular and Editor's picks, each drawing a different row: dated rows, ranked rows with read counts, and rows with an editor's note.
- Pro
Tags FAQ
Topics and filtersA tagged FAQ for a children's book club: a side header with a tag cloud, and questions that carry their own tag buttons, both filtering the same list.