# Tags Composition 1 - Pre-selected tags

> Tags trigger pre-populated with multiple TagsValue badges on initial load.

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

- Page, with a live preview: https://shadcn.exchange/r/shadcnblocks/tags-tags-composition-1
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/shadcnblocks/tags-tags-composition-1-light-4065fc601567651e.png
- Registry item: https://shadcnblocks.com/r/tags-tags-composition-1.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://shadcnblocks.com/r/tags-tags-composition-1.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: `https://www.kibo-ui.com/r/tags.json`

## Files

### `example/tags/tags-composition-1.tsx`

```tsx
"use client";

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

import {
  Tags,
  TagsContent,
  TagsGroup,
  TagsInput,
  TagsItem,
  TagsList,
  TagsTrigger,
  TagsValue,
} from "@/components/kibo-ui/tags";
export const title = "Pre-selected tags";

const tags = [
  { value: "urgent", label: "Urgent" },
  { value: "review", label: "Needs review" },
  { value: "approved", label: "Approved" },
  { value: "archived", label: "Archived" },
];

const Example = () => {
  const [selected, setSelected] = useState<string[]>(["urgent", "review"]);

  const toggle = (value: string) => {
    setSelected((current) =>
      current.includes(value)
        ? current.filter((item) => item !== value)
        : [...current, value],
    );
  };

  const remove = (value: string) => {
    setSelected((current) => current.filter((item) => item !== value));
  };

  return (
    <div className="w-full max-w-lg">
      <Tags>
        <TagsTrigger>
          {selected.map((value) => {
            const tag = tags.find((item) => item.value === value);
            return (
              <TagsValue key={value} onRemove={() => remove(value)}>
                {tag?.label ?? value}
              </TagsValue>
            );
          })}
        </TagsTrigger>
        <TagsContent>
          <TagsInput placeholder="Add or remove tags..." />
          <TagsList>
            <TagsGroup heading="Status">
              {tags.map((tag) => (
                <TagsItem
                  key={tag.value}
                  value={tag.value}
                  onSelect={() => toggle(tag.value)}
                >
                  <Check
                    className={cn(
                      "size-4",
                      selected.includes(tag.value)
                        ? "opacity-100"
                        : "opacity-0",
                    )}
                  />
                  {tag.label}
                </TagsItem>
              ))}
            </TagsGroup>
          </TagsList>
        </TagsContent>
      </Tags>
    </div>
  );
};

export default Example;
```
