Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Item examples · Interactive

Item in Dropdown for React

A Select button that opens a menu of people, each row an item with an avatar, a username and a masked email.

Framework
UI library

A menu option sometimes needs more than a word: a face, a name and an address to tell people apart. This React example puts a small Item inside each Dropdown Menu item, with an Avatar in ItemMedia and the username and masked email in ItemContent. The menu item drops its padding (p-0) and the Item brings its own (p-2, w-full), the menu is w-72 wide and opens under the outline Select button, aligned to its end.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

When should menu options use an Item instead of plain text?

When each option carries more than one piece of information, like a name and an email, or needs a picture to be recognized. For short labels such as Edit or Delete, plain text and an icon are enough. The menu's keyboard handling is the same either way.

Why p-0 on the menu item and p-2 on the Item?

Both parts have padding, and together they would double it. Removing it from the menu item and setting it on the Item lets one part own the spacing, and w-full makes the Item fill the row so the highlight covers it edge to edge.

How does ItemMedia hold the avatar?

ItemMedia keeps the avatar from shrinking and aligns it with the text; when the row has a description, it moves to the top of the row. The Avatar here is its default size, and AvatarFallback shows the username's first letter if the picture doesn't load.

Why use size sm for Items in a menu?

size="sm" tightens the Item's gap and padding so more people fit before the menu scrolls. The example then sets p-2 on top of it to match the menu's own items. For an even tighter menu there's xs.

How do I set the width of the menu?

Put a width class on the menu content, w-72 here, and give the Item w-full. A fixed width keeps the menu from jumping as rows change; the title clamps to one line and the description to two if a value is longer.

Are Items inside a menu accessible?

Yes. The menu item carries the menuitem role and the keyboard handling, and the Item inside is only its content. Choosing a row closes the menu. To act on the choice: Set onClick on the item.