Skip to main content

Usage

import { Tag } from '@kivora/react';

<Tag onRemove={() => removeTag(id)}>TypeScript</Tag>

Examples

Basic Tag

<Tag>React</Tag>

With Remove Handler

function TagExample() {
  const [tags, setTags] = useState(['React', 'TypeScript', 'Vite']);

  const removeTag = (index: number) => {
    setTags(tags.filter((_, i) => i !== index));
  };

  return (
    <div className="flex gap-2">
      {tags.map((tag, i) => (
        <Tag key={i} onRemove={() => removeTag(i)}>
          {tag}
        </Tag>
      ))}
    </div>
  );
}

Variants

<Tag variant="default">Default</Tag>

Sizes

<Tag size="sm" onRemove={() => {}}>Small</Tag>

Disabled

<Tag disabled onRemove={() => console.log('will not fire')}>
  Disabled Tag
</Tag>
Disabled tags have reduced opacity and the remove button is non-interactive.

Tag List

const skills = [
  { id: 1, name: 'React', variant: 'info' },
  { id: 2, name: 'TypeScript', variant: 'success' },
  { id: 3, name: 'Node.js', variant: 'default' },
];

function SkillTags() {
  const [items, setItems] = useState(skills);

  return (
    <div className="flex flex-wrap gap-2">
      {items.map(skill => (
        <Tag
          key={skill.id}
          variant={skill.variant}
          onRemove={() => setItems(items.filter(s => s.id !== skill.id))}
        >
          {skill.name}
        </Tag>
      ))}
    </div>
  );
}

Props

children
React.ReactNode
required
Tag content
onRemove
() => void
Callback when remove button is clicked. If provided, displays a close button
variant
'default' | 'success' | 'warning' | 'error' | 'info'
default:"default"
Visual style variant
size
'sm' | 'md'
default:"md"
Tag size
disabled
boolean
default:false
Disable the remove button and apply disabled styling
className
string
Additional CSS classes

Accessibility

  • Remove button has aria-label with tag content
  • Uses semantic <button> element for close action
  • Disabled state uses disabled attribute
  • Keyboard accessible with proper focus management
  • Focus ring on close button for keyboard navigation

Comparison with Badge and Chip

  • Tag: Dismissible labels, typically for filters or user-added items
  • Badge: Static status indicators, non-interactive
  • Chip: Interactive toggleable items, can be read-only

Build docs developers (and LLMs) love