Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Menubar examples · Standard

Menubar with Radio Groups for React

A View menu with a Layout choice where exactly one of Grid, List or Columns is checked.

Framework
UI library

A view is a grid, a list or columns, never two at once. This menubar's View menu holds a Layout label and Grid, List and Columns as radio rows, with Grid checked to start. It fits file browsers, galleries and dashboards with switchable layouts.

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

How does the layout choice stay selected?

The layout is one value, grid to start, kept in the component, so the check is still on it when View reopens. MenubarRadioGroup takes value, and onValueChange receives the new value. Each MenubarRadioItem has its value.

What happens when I choose List?

The value becomes list, the check moves from Grid to List, and the menu closes. Switch your view where the value changes.

What opens this menu?

A MenubarTrigger that reads View, in the bar's only MenubarMenu.

How do I add a command that is not a layout?

Put a MenubarSeparator after the radio group, then a plain MenubarItem, such as Refresh. It runs an action and doesn't take part in the choice.

Can I change the layout from the keyboard?

Yes. Open View with Enter, Space or Arrow Down, move with the arrow keys, and press Enter or Space to pick a layout.

Is Layout itself a choice?

No. It's a MenubarLabel, first inside the radio group, that names it. It can't be focused or picked.