# Emoji Picker

A searchable, virtualized emoji picker recipe with recent selections, skin tones, previews, and optional Popover composition.

Emoji Picker provides searchable Unicode emoji selection without making a large locale dataset part of the Zenos core package. It supports keyboard navigation, virtualized category rendering, skin tones, persisted recent selections, and a hovered or keyboard-active preview.

<p className="zenos-recipe-source">
  Powered by <a href="https://frimousse.liveblocks.io/">Frimousse</a> for emoji data resolution,
  search, keyboard behavior, and virtualization. Zenos owns the semantic styling, recent-selection
  state, preview, and Popover composition.
</p>

```bash
pnpm dlx @zentara-co/zenos-cli add emoji-picker
npx @zentara-co/zenos-cli add emoji-picker
yarn dlx @zentara-co/zenos-cli add emoji-picker
bunx @zentara-co/zenos-cli add emoji-picker
```

The command installs `frimousse` and adds `emoji-picker.tsx` to the consumer project. Import the editable recipe through the path configured by your application:

```tsx
import { EmojiPicker } from "./components/emoji-picker";
```

## Basic usage

`EmojiPicker` renders the complete search, recent row, virtualized list, skin-tone control, loading and empty states, and active-emoji preview. Handle the selected object when the application needs both the Unicode character and its localized label.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { EmojiPicker } from "@docs/src/recipes/emoji-picker/emoji-picker";

function EmojiPickerRecipeExample() {
  const [selection, setSelection] = useState("No emoji selected");

  return (
    <Stack gap="3" align="center">
      <EmojiPicker
        defaultRecent={["👍", "👏", "🥳"]}
        storageKey={null}
        onEmojiSelect={({ emoji, label }) => setSelection(`${emoji} ${label}`)}
      />
      <Text color="subtle" size="s" aria-live="polite">
        {selection}
      </Text>
    </Stack>
  );
}
```

```tsx
<EmojiPicker
  onEmojiSelect={({ emoji, label }) => {
    setReaction(emoji);
    announce(`${label} selected`);
  }}
/>
```

```text
EmojiPicker
├── EmojiPicker.Root
│   ├── EmojiPicker.Search
│   ├── EmojiPicker.SkinToneSelector
│   ├── EmojiPicker.Recents
│   ├── EmojiPicker.Viewport
│   │   ├── EmojiPicker.Loading
│   │   ├── EmojiPicker.Empty
│   │   └── EmojiPicker.List
│   └── EmojiPicker.Preview
└── Optional Popover composition
    ├── EmojiPickerPopover
    ├── EmojiPickerTrigger
    └── EmojiPickerContent
```

## Popover composition

Use the Popover wrappers for reaction buttons, comment editors, and compact toolbars. The content closes after selection by default. Set `closeOnSelect={false}` when users should add several emojis without reopening it.

```tsx
import { useState } from "react";
import { IconButton, Text } from "@zentara-co/zenos-ui";
import { EmojiPickerContent, EmojiPickerPopover, EmojiPickerTrigger } from "@docs/src/recipes/emoji-picker/emoji-picker";

function EmojiPickerPopoverExample() {
  const [emoji, setEmoji] = useState("🙂");

  return (
    <div className="flex items-center gap-3">
      <EmojiPickerPopover>
        <EmojiPickerTrigger
          render={
            <IconButton aria-label="Choose reaction" variant="primary">
              <span aria-hidden="true" className="text-lg">
                {emoji}
              </span>
            </IconButton>
          }
        />
        <EmojiPickerContent
          align="start"
          storageKey={null}
          onEmojiSelect={(selection) => setEmoji(selection.emoji)}
        />
      </EmojiPickerPopover>
      <Text color="subtle" size="s">
        Open the picker to change the reaction.
      </Text>
    </div>
  );
}
```

```tsx
<EmojiPickerPopover>
  <EmojiPickerTrigger
    render={
      <IconButton aria-label="Choose reaction">
        <SmileyIcon />
      </IconButton>
    }
  />
  <EmojiPickerContent onEmojiSelect={({ emoji }) => setReaction(emoji)} />
</EmojiPickerPopover>
```

`EmojiPickerContent` accepts the same picker props as `EmojiPicker`, plus `align`, `side`, `sideOffset`, and `popoverClassName` for placement and surface customization.

## Compose a custom layout

Every visible part is exported. Use the parts when the product needs different ordering, custom loading copy, a compact viewport, or no preview. Keep `Search`, `Viewport`, `List`, and any Frimousse state-aware parts inside `EmojiPicker.Root`.

```tsx
<EmojiPicker.Root onEmojiSelect={handleSelect}>
  <EmojiPicker.Search placeholder="Find a reaction" />
  <EmojiPicker.Recents label="Your reactions" />
  <EmojiPicker.Viewport className="h-48">
    <EmojiPicker.Loading>Loading reactions…</EmojiPicker.Loading>
    <EmojiPicker.Empty>{({ search }) => `No match for “${search}”.`}</EmojiPicker.Empty>
    <EmojiPicker.List />
  </EmojiPicker.Viewport>
</EmojiPicker.Root>
```

`EmojiPicker.List` accepts Frimousse's `components` override. Provide any subset of `CategoryHeader`, `Row`, and `Emoji`; Zenos defaults remain in place for omitted renderers.

## Recent selections

Uncontrolled recents persist to `localStorage` under `zenos-emoji-picker-recent`. The picker de-duplicates the selected emoji, moves it to the start, and retains eight items by default.

- Set `storageKey={null}` to disable persistence.
- Change `storageKey` when separate product areas need independent history.
- Use `recent`, `onRecentChange`, and `recentLimit` when application state owns the list.
- Use `defaultRecent` to seed an uncontrolled picker.
- Set `showRecents={false}` to hide the row while selection history continues updating.

Persisted recents contain emoji characters only. Do not put user content, identifiers, or private metadata in the storage key.

## Emoji data and localization

Frimousse fetches localized Emojibase data on demand by default and caches it. Set `locale` to a supported locale, or provide `resolveEmojiData` when the application needs a custom locale, a reduced dataset, deterministic tests, or an offline build.

```tsx
<EmojiPicker
  locale="id"
  emojibaseUrl="https://static.example.com/emojibase-data"
  onEmojiSelect={handleSelect}
/>
```

Self-host the dataset when Content Security Policy or offline requirements disallow the default CDN. Keep the resolver stable between renders; Frimousse reloads when the locale or dataset options change.

## Root API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| onEmojiSelect | (emoji: { emoji: string; label: string }) => void | — | Receives the selected Unicode character and localized label. |
| locale | Locale | en | Locale used to resolve labels, tags, categories, and search terms. |
| columns | number | 8 | Number of emoji buttons in each virtualized row. |
| skinTone | none \| light \| medium-light \| medium \| medium-dark \| dark | none | Initial skin-tone preference passed to Frimousse. |
| recent / defaultRecent | readonly string[] | — | Controlled or initial recent emoji characters. |
| onRecentChange | (recent: readonly string[]) => void | — | Called after selection reorders the recent list. |
| recentLimit | number | 8 | Maximum recent selections retained after de-duplication. |
| storageKey | string \| null | zenos-emoji-picker-recent | Persistence key, or null to disable localStorage. |
| showRecents / showPreview | boolean | true | Toggles the composed picker sections without changing selection behavior. |
| resolveEmojiData | EmojiDataResolver | — | Custom synchronous or asynchronous locale dataset resolver. |

The root forwards native `div` props and its ref. Visible parts accept `className`, merge it after their defaults, and expose stable `data-slot` attributes.

## Accessibility

Frimousse owns list navigation and search interaction. Zenos preserves those semantics while adding visible focus states and accessible labels for recent selections.

- Give an icon-only `EmojiPickerTrigger` an accessible name describing the action.
- Keep emoji labels from the selected object when announcing a selection; the character alone may not be announced consistently.
- Do not remove the focus indicator from emoji buttons or search.
- Keep search before the virtualized list in reading order.
- Test keyboard selection, search results, and Popover dismissal at the product's supported zoom levels.
- If the picker opens in a chat composer, restore focus to the trigger after it closes.

## Review checklist

- [ ] The trigger has a meaningful accessible name.
- [ ] Selection uses both the emoji character and its localized label where needed.
- [ ] The chosen locale or custom resolver is available in production.
- [ ] Content Security Policy allows the data URL, or the dataset is self-hosted.
- [ ] Search, arrow-key navigation, Enter selection, and Escape dismissal work.
- [ ] Recent-history persistence matches the product's privacy expectations.
- [ ] Light, dark, narrow, RTL, loading, empty, and long-label states are verified.

Source: https://zenos-ui.pages.dev/recipes/emoji-picker/