# Combobox Grouped 3 - Nested/Hierarchical Groups

> Nested/Hierarchical Groups combobox using shadcn Command and Popover.

A shadcn/ui block from the [@shadcnblocks](https://shadcnblocks.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/shadcnblocks/combobox-combobox-grouped-3).

- Page, with a live preview: https://shadcn.exchange/r/shadcnblocks/combobox-combobox-grouped-3
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/shadcnblocks/combobox-combobox-grouped-3-light-5079e5b8f66dec44.png
- Registry item: https://shadcnblocks.com/r/combobox-combobox-grouped-3.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://shadcnblocks.com/r/combobox-combobox-grouped-3.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `cn`, `lucide-react`
- Registry items: `button`, `command`, `popover`

## Files

### `example/combobox/combobox-grouped-3.tsx`

```tsx
"use client";

import { Check, ChevronRight, ChevronsUpDown } from "lucide-react";
import { useState } from "react";
import { cn } from "cn";

import { Button } from "@/components/ui/button";
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover";

export const title = "Nested/Hierarchical Groups";

const regions = {
  "North America": [
    { value: "us", label: "United States" },
    { value: "ca", label: "Canada" },
    { value: "mx", label: "Mexico" },
  ],
  Europe: [
    { value: "uk", label: "United Kingdom" },
    { value: "de", label: "Germany" },
    { value: "fr", label: "France" },
  ],
  Asia: [
    { value: "jp", label: "Japan" },
    { value: "cn", label: "China" },
    { value: "in", label: "India" },
  ],
};

const Example = () => {
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState("");

  return (
    <Popover onOpenChange={setOpen} open={open}>
      <PopoverTrigger asChild>
        <Button
          aria-expanded={open}
          className="w-[250px] justify-between"
          role="combobox"
          variant="outline"
        >
          {value
            ? Object.values(regions)
                .flat()
                .find((item) => item.value === value)?.label
            : "Select country..."}
          <ChevronsUpDown className="ml-2 size-4 shrink-0 opacity-50" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[250px] p-0">
        <Command>
          <CommandInput placeholder="Search country..." />
          <CommandList>
            <CommandEmpty>No country found.</CommandEmpty>
            {Object.entries(regions).map(([region, countries]) => (
              <CommandGroup heading={region} key={region}>
                {countries.map((country) => (
                  <CommandItem
                    key={country.value}
                    onSelect={(currentValue) => {
                      setValue(currentValue === value ? "" : currentValue);
                      setOpen(false);
                    }}
                    value={country.value}
                  >
                    <Check
                      className={cn(
                        "mr-2 size-4",
                        value === country.value ? "opacity-100" : "opacity-0",
                      )}
                    />
                    <ChevronRight className="mr-2 size-3 opacity-50" />
                    {country.label}
                  </CommandItem>
                ))}
              </CommandGroup>
            ))}
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>
  );
};

export default Example;
```
