# Emoji Reaction Button

A toggleable emoji reaction with a count, like a Slack reaction.

- Category: Core Elements
- Page: https://wunderui.com/components/emoji-reaction-button
- Tier: Free

## Install

```bash
npx wunderui-cli add emoji-reaction-button
```

## Import

```tsx
import { EmojiReactionButton, EmojiReactionButtonProps } from "@/components/wunderui/emoji-reaction-button"
```

## Minimal usage

Then use it:

```tsx
import { useState } from "react"
import { EmojiReactionButton } from "@/components/ui/emoji-reaction-button"

export function Reaction() {
  const [active, setActive] = useState(false)

  return (
    <EmojiReactionButton
      emoji="🔥"
      count={11 + (active ? 1 : 0)}
      active={active}
      onToggle={() => setActive((value) => !value)}
    />
  )
}
```

Expected result: You see a pill with a fire emoji and a count of 11. Press it and it turns indigo with the count at 12; press again to go back.

## Usage

```tsx
import { useState } from "react"
import { EmojiReactionButton } from "@/components/ui/emoji-reaction-button"

export function Example() {
  const [active, setActive] = useState(false)

  return (
    <EmojiReactionButton
      emoji="🔥"
      count={11 + (active ? 1 : 0)}
      active={active}
      onToggle={() => setActive((value) => !value)}
    />
  )
}
```

## When to use

### Use Emoji Reaction Button for

- Reactions under a message, a comment, a post or a changelog entry
- Quick feedback with a visible tally, such as helpful or not helpful
- A small set of choices where people see how many others chose the same

### Use something else

- [Toggle](https://wunderui.com/components/toggle) for an on or off option for the person alone, such as bold or mute
- [Rating](https://wunderui.com/components/rating) for a score from one to five
- [Badge](https://wunderui.com/components/badge) for a read-only label or count that cannot be pressed

## Keyboard

The button is a native button, so the browser provides focus and activation.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous reaction. Each one is a tab stop. |
| `Enter` or `Space` | Switches the reaction on or off by calling `onToggle`. The screen reader announces the new pressed state. |

## Behavior

What the button does with state, names and motion.

- **Controlled:** The button keeps no state. The active state and count come from you, and every press calls the toggle handler without arguments, so nothing changes until you update them.
- **Pressed state:** The pressed state follows the active one, so assistive technology announces pressed or not pressed. A reaction is a toggle, not a link or a menu.
- **Name:** The accessible name is the emoji followed by the count, for example fire 12. It cannot be overridden, so say what the reaction means in text near the row.
- **States:** Off has a neutral border, secondary text and hover and pressed fills; on has an indigo tint, border and text. Focus shows the indigo border and a 2 px ring.
- **Size:** The pill is 26 px high with 8 px of side padding and 12 px text. It does not grow with the count, it only gets one digit wider at a time.
- **Numbers:** The count is a plain number, so 1284 reads 1284. For large counts keep the figure short, or show a tally of your own beside the buttons.
- **Motion:** Border, fill and text colour fade on the fast duration when the state changes. Nothing moves or scales.
- **Reduced motion:** There is no movement to remove, so reduced motion changes nothing. The colour change is a short fade and stays.

## Anatomy

- `EmojiReactionButton`: A native button that shows an emoji and a count and reports whether it is pressed. It is controlled: you hold the active state and count and change them in the toggle handler.
- `Pill`: The 26 px high capsule with a 1 px border and a small gap between emoji and count. Off, it has a neutral border and secondary text; on, an indigo tint with indigo border and text.
- `Emoji`: The emoji character, at the text size of the pill. It is part of the button's accessible name, so a screen reader reads the emoji and then the count.
- `Count`: The number of people who reacted, shown as a plain number after the emoji. It does not change by itself when pressed, so update it in the toggle handler.

## Best practices

### Do

- Keep the active state and the count together and change them in the toggle handler: turning on adds one, turning off takes one away.
- Show only the reactions that exist, and open an Emoji Picker from a small icon button for the rest. A reaction that drops to zero should disappear.
- Put the buttons in a wrapping row with a gap, so they wrap on a narrow screen instead of overflowing.
- Where the product shows no emoji, pass an icon and a label; the label names the button ("Agree: 3").

### Don't

- Don't use it as a general toggle. It is for a reaction with a count; for an on or off option in a toolbar use Toggle.
- Don't show a count of zero. A reaction nobody has chosen is not shown, and the Emoji Picker adds it again.
- Don't use an emoji as the only information. Where the meaning matters, say it in text near the buttons.

## API reference

### EmojiReactionButton

| Prop | Type | Default | Description |
|---|---|---|---|
| count* | number |  | The number of people who reacted. It is shown as a plain number and does not change on its own: update it together with `active`. |
| active | boolean |  | Whether the reaction is switched on. It sets `aria-pressed` and the indigo tint. Off by default. |
| className | string |  | Extra classes for the button, for example a margin in a row. |
| emoji | string |  | The emoji to show, as a character. It is the first part of the button's accessible name. |
| icon | React.ReactNode |  | The reaction as an icon (14 px, e.g. a thumbs up), in place of `emoji`. |
| label | string |  | What the reaction means ("Agree", "Thanks"): the accessible name is "<label>: <count>". Needed with an `icon`, which has no text of its own; `aria-label` replaces it entirely. |
| onToggle | () => void |  | Called without arguments when the button is pressed. Flip `active` and change the count here. |

Also accepts React.ButtonHTMLAttributes attributes.

## Examples

### Content: the emoji and the size of the count

```tsx
import { useState } from "react"
import { EmojiReactionButton } from "@/components/ui/emoji-reaction-button"

export function Example() {
  const [active, setActive] = useState(false)

  return (
    <EmojiReactionButton
      emoji="🔥"
      count={12 + (active ? 1 : 0)}
      active={active}
      onToggle={() => setActive((value) => !value)}
    />
  )
}
```

## In context

### Pull request thread: reactions under each comment

Every comment keeps its own reactions. Pressing one switches it on and adds you to the count, and pressing it again takes you out.

```tsx
import { useState } from "react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { EmojiReactionButton } from "@/components/ui/emoji-reaction-button"

type Reaction = { emoji: string; count: number; active: boolean }
type Comment = { id: string; author: string; initials: string; text: string; reactions: Reaction[] }

const COMMENTS: Comment[] = [
  {
    id: "export",
    author: "Priya Raman",
    initials: "PR",
    text: "The new export keeps the column order we agreed on.",
    reactions: [
      { emoji: "👍", count: 4, active: true },
      { emoji: "🎉", count: 2, active: false },
    ],
  },
  {
    id: "deploy",
    author: "Tomás Ferreira",
    initials: "TF",
    text: "Merged after the second review. The deploy goes out at 3 pm.",
    reactions: [
      { emoji: "🚀", count: 5, active: false },
      { emoji: "👀", count: 1, active: false },
    ],
  },
]

export function Example() {
  const [comments, setComments] = useState(COMMENTS)

  const toggle = (id: string, emoji: string) =>
    setComments((list) =>
      list.map((comment) =>
        comment.id !== id
          ? comment
          : {
              ...comment,
              reactions: comment.reactions.map((r) =>
                r.emoji === emoji ? { ...r, active: !r.active, count: r.count + (r.active ? -1 : 1) } : r
              ),
            }
      )
    )

  return (
    <ul className="flex w-full max-w-md flex-col divide-y divide-border rounded-xl border border-border bg-card">
      {comments.map((comment) => (
        <li key={comment.id} className="flex flex-col gap-3 p-4">
          <div className="flex items-center gap-2">
            <Avatar size="sm">
              <AvatarFallback>{comment.initials}</AvatarFallback>
            </Avatar>
            <span className="text-sm font-medium text-foreground">{comment.author}</span>
          </div>
          <p className="text-sm text-text-secondary">{comment.text}</p>
          <div className="flex flex-wrap gap-2">
            {comment.reactions.map((r) => (
              <EmojiReactionButton
                key={r.emoji}
                emoji={r.emoji}
                count={r.count}
                active={r.active}
                onToggle={() => toggle(comment.id, r.emoji)}
              />
            ))}
          </div>
        </li>
      ))}
    </ul>
  )
}
```

### Article feedback: one vote each

Two reaction buttons act as a single choice. Choosing the other answer moves your vote, and choosing the same one again takes it back.

```tsx
import { useState } from "react"
import { EmojiReactionButton } from "@/components/ui/emoji-reaction-button"

type Vote = "up" | "down" | null

export function Example() {
  const [vote, setVote] = useState<Vote>(null)

  const choose = (next: Exclude<Vote, null>) => setVote((current) => (current === next ? null : next))

  return (
    <div className="flex w-full max-w-md flex-col gap-3 rounded-xl border border-border bg-card p-4">
      <p className="text-sm font-medium text-foreground">Was this article helpful?</p>
      <div className="flex flex-wrap gap-2">
        <EmojiReactionButton emoji="👍" count={128 + (vote === "up" ? 1 : 0)} active={vote === "up"} onToggle={() => choose("up")} />
        <EmojiReactionButton emoji="👎" count={9 + (vote === "down" ? 1 : 0)} active={vote === "down"} onToggle={() => choose("down")} />
      </div>
      <p className="text-sm text-text-secondary">One vote each. Choosing the other answer moves your vote.</p>
    </div>
  )
}
```

### Icons instead of emoji

Where the product shows no emoji, pass an `icon` and a `label`: the button reads "Agree: 3" and keeps its pressed state.

```tsx
<EmojiReactionButton icon={<ThumbsUp />} label="Agree" count={3} active onToggle={toggle} />
```

## For AI agents

`get_component("emoji-reaction-button")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
