# Emoji picker

> Search a configurable emoji list with categories, session recents and skin tones, backed by a native select.

- Kind: ui · Category: Forms · Interactivity: script
- Install: `npx shadcn@latest add @haze/emoji-picker`
- File: `src/components/haze/ui/emoji-picker.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/emoji-picker

## Use when
- A status or update form needs a compact searchable set of named emoji.
- Products should control the emoji vocabulary while keeping a native selection fallback.

## Avoid when
- Use reactions for a small fixed collection of independent acknowledgments.
- Use select when only a few textual status choices are necessary.

## Alternatives
- [reactions](https://hazeui.com/ui/reactions.md)
- [select](https://hazeui.com/ui/select.md)
- [combobox](https://hazeui.com/ui/combobox.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique caller supplied prefix for the control and its associated content. |
| name | `string` | id | no | Name submitted by the native form control. |
| label | `string` | Choose an emoji | no | Legend describing the emoji selection. |
| value | `string` | Empty | no | Initially selected emoji string. |
| items | `{ emoji: string; label: string; category: string; keywords?: string; tones?: string[] }[]` | 22 curated emoji | no | Searchable vocabulary; tones lists the five standard skin variations when supported. |
| disabled | `boolean` | false | no | Prevents user changes through the native disabled state. |
| class | `string` |  | no | Additional classes on this component's outer wrapper. |
| [key: string] | `unknown` |  | no | Additional attributes applied to the submitted native select. |

## Accessibility
- The native select is labelled and stays available before and after enhancement, so the selected Unicode value always submits normally.
- Search filters by label, keywords and emoji, and a polite region reports matching counts and selections.
- The emoji buttons form a labelled group with one Tab stop; arrow keys, Home and End navigate the visible buttons.
- Category selection is expressed with pressed state and skin tone uses a labelled native select; variants are only offered for supplied supported gestures.
- Recent choices are held only in this component's session, and the default curated list is intentionally smaller than the full Unicode emoji catalog.
- Key Down from search: Focus the first matching emoji.
- Key Arrows / Home / End: Move among visible emoji choices.
- Key Enter / Space: Select the focused emoji.
- Key Escape in search: Clear a nonempty query without closing a surrounding overlay.

## Agent prompts

### Install and use

Install the Haze UI component "Emoji picker" with `npx shadcn@latest add @haze/emoji-picker`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import EmojiPicker from "@/components/haze/ui/emoji-picker.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/emoji-picker.md

### Customize with real content

Adapt the Haze emoji-picker ui for our product. Replace the demo values of these props with our real content: id, name, label, value, items, disabled, class, [key: string]. Keep the layout, the heading level rules and these accessibility details: The native select is labelled and stays available before and after enhancement, so the selected Unicode value always submits normally. Search filters by label, keywords and emoji, and a polite region reports matching counts and selections. The emoji buttons form a labelled group with one Tab stop; arrow keys, Home and End navigate the visible buttons. Category selection is expressed with pressed state and skin tone uses a labelled native select; variants are only offered for supplied supported gestures. Recent choices are held only in this component's session, and the default curated list is intentionally smaller than the full Unicode emoji catalog. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using emoji-picker, check it fits: use it when a status or update form needs a compact searchable set of named emoji.; products should control the emoji vocabulary while keeping a native selection fallback.. Avoid it when use reactions for a small fixed collection of independent acknowledgments.; use select when only a few textual status choices are necessary.. Alternatives: @haze/reactions, @haze/select, @haze/combobox.

## Example requests that should lead here
- Add a searchable project status emoji picker with named categories
- Offer a configurable emoji vocabulary with native select fallback and gesture skin tones

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Emoji { emoji: string; label: string; category: string; keywords?: string; tones?: string[]; }
interface Props {
  id: string;
  name?: string;
  label?: string;
  value?: string;
  items?: Emoji[];
  disabled?: boolean;
  class?: string;
  [key: string]: unknown;
}
const { id, name = id, label = "Choose an emoji", value = "", items = [
  { emoji: "😀", label: "Grinning face", category: "Faces", keywords: "happy smile" }, { emoji: "😊", label: "Smiling face", category: "Faces", keywords: "happy kind" }, { emoji: "😂", label: "Tears of joy", category: "Faces", keywords: "laugh funny" }, { emoji: "🤔", label: "Thinking face", category: "Faces", keywords: "consider question" }, { emoji: "😎", label: "Smiling face with sunglasses", category: "Faces", keywords: "cool" }, { emoji: "🥳", label: "Partying face", category: "Faces", keywords: "celebrate" },
  { emoji: "👍", label: "Thumbs up", category: "Gestures", keywords: "like approve helpful", tones: ["👍🏻", "👍🏼", "👍🏽", "👍🏾", "👍🏿"] }, { emoji: "👋", label: "Waving hand", category: "Gestures", keywords: "hello goodbye", tones: ["👋🏻", "👋🏼", "👋🏽", "👋🏾", "👋🏿"] }, { emoji: "👏", label: "Clapping hands", category: "Gestures", keywords: "applause well done", tones: ["👏🏻", "👏🏼", "👏🏽", "👏🏾", "👏🏿"] }, { emoji: "🙏", label: "Folded hands", category: "Gestures", keywords: "thanks please", tones: ["🙏🏻", "🙏🏼", "🙏🏽", "🙏🏾", "🙏🏿"] },
  { emoji: "💛", label: "Yellow heart", category: "Symbols", keywords: "love care" }, { emoji: "✨", label: "Sparkles", category: "Symbols", keywords: "new magic" }, { emoji: "✅", label: "Check mark", category: "Symbols", keywords: "done complete" }, { emoji: "💡", label: "Light bulb", category: "Symbols", keywords: "idea" }, { emoji: "🔥", label: "Fire", category: "Symbols", keywords: "popular" }, { emoji: "🎉", label: "Party popper", category: "Symbols", keywords: "celebration launch" },
  { emoji: "🌿", label: "Herb", category: "Nature", keywords: "plant calm" }, { emoji: "🌻", label: "Sunflower", category: "Nature", keywords: "flower" }, { emoji: "🌈", label: "Rainbow", category: "Nature", keywords: "weather" }, { emoji: "🌙", label: "Crescent moon", category: "Nature", keywords: "night" }, { emoji: "☀️", label: "Sun", category: "Nature", keywords: "day bright" }, { emoji: "🌱", label: "Seedling", category: "Nature", keywords: "growth" },
], disabled, class: className, ...rest } = Astro.props;
const categories = [...new Set(items.map((item) => item.category))];
---
<fieldset data-haze-emoji-picker data-items={JSON.stringify(items)} disabled={disabled} class={cn("grid w-full min-w-0 gap-3 rounded-xl border border-border bg-card p-3 text-card-foreground", className)}>
  <legend class="px-1 text-[0.8125rem]/5 font-medium">{label}</legend>
  <div data-emoji-tools hidden class="grid gap-3">
    <div class="grid gap-1.5"><label for={`${id}-search`} class="text-[0.8125rem]/5 font-medium">Search emoji</label><input id={`${id}-search`} type="search" data-emoji-search placeholder="Try happy or thanks" autocomplete="off" class="h-10 w-full min-w-0 rounded-lg border border-frame-input bg-field px-3 text-sm tracking-[-0.01em] text-foreground placeholder:text-muted-foreground transition-[border-color,box-shadow] duration-150 ease-snappy hover:border-frame-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden" /></div>
    <div data-emoji-categories class="flex flex-wrap gap-1.5" role="group" aria-label="Emoji categories">{["All", ...categories, "Recent"].map((category) => <button type="button" data-emoji-category={category} aria-pressed={category === "All" ? "true" : "false"} disabled={category === "Recent"} class="min-h-8 cursor-pointer rounded-full border border-frame bg-muted px-2.5 text-xs font-medium text-muted-foreground transition-[background-color,border-color,color,scale] duration-150 ease-snappy hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-[0.97] active:duration-75 motion-reduce:transition-none motion-reduce:active:scale-100 aria-pressed:border-border-strong aria-pressed:bg-accent aria-pressed:text-foreground disabled:cursor-default disabled:opacity-50">{category}</button>)}</div>
    <div data-emoji-grid role="group" aria-label="Matching emoji" class="grid grid-cols-[repeat(auto-fill,minmax(2rem,1fr))] gap-1">{items.map((item, index) => <button type="button" data-emoji-index={index} aria-label={item.label} aria-pressed={value === item.emoji ? "true" : "false"} tabindex={index === 0 ? 0 : -1} class="grid min-h-9 cursor-pointer place-items-center rounded-md text-xl/7 transition-[background-color,scale] duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-90 active:duration-75 motion-reduce:transition-none motion-reduce:active:scale-100 aria-pressed:bg-accent aria-pressed:outline aria-pressed:outline-1 aria-pressed:-outline-offset-1 aria-pressed:outline-border-strong">{item.emoji}</button>)}</div>
    <div class="grid gap-1.5"><label for={`${id}-tone`} class="text-[0.8125rem]/5 font-medium">Skin tone for supported gestures</label><select id={`${id}-tone`} data-emoji-tone class="h-10 min-w-0 rounded-lg border border-frame bg-field px-2 text-sm text-foreground transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden">{["Default", "Light", "Medium light", "Medium", "Medium dark", "Dark"].map((tone, index) => <option value={index}>{tone}</option>)}</select></div>
  </div>
  <div class="grid gap-1.5 border-t border-border pt-3"><label for={id} class="text-[0.8125rem]/5 font-medium">Selected emoji</label><select id={id} name={name} data-emoji-value class="h-10 w-full min-w-0 rounded-lg border border-frame bg-field px-2 text-sm text-foreground transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden" {...rest}><option value="">Choose an emoji</option>{items.map((item) => <option value={item.emoji} selected={value === item.emoji}>{item.emoji} {item.label}</option>)}</select></div>
  <p data-emoji-status role="status" class="text-[0.8125rem]/5 text-muted-foreground">{items.length} emoji available. Supply your own list to extend the picker.</p>
</fieldset>
<script>
  type EmojiChoice = { emoji: string; label: string; category: string; keywords?: string; tones?: string[] };
  function enhance(root: HTMLFieldSetElement) {
    if (root.hasAttribute("data-enhanced")) return;
    const search = root.querySelector<HTMLInputElement>("[data-emoji-search]");
    const select = root.querySelector<HTMLSelectElement>("[data-emoji-value]");
    const tone = root.querySelector<HTMLSelectElement>("[data-emoji-tone]");
    const grid = root.querySelector<HTMLElement>("[data-emoji-grid]");
    const status = root.querySelector<HTMLElement>("[data-emoji-status]");
    if (!search || !select || !tone || !grid || !status) return;
    const items = JSON.parse(root.dataset.items || "[]") as EmojiChoice[];
    const buttons = Array.from(grid.querySelectorAll<HTMLButtonElement>("[data-emoji-index]"));
    const categories = Array.from(root.querySelectorAll<HTMLButtonElement>("[data-emoji-category]"));
    let category = "All", recent: number[] = [], visible = buttons.slice();
    const symbol = (item: EmojiChoice) => Number(tone.value) > 0 ? item.tones?.[Number(tone.value) - 1] || item.emoji : item.emoji;
    const render = () => {
      const query = search.value.trim().toLocaleLowerCase();
      buttons.forEach((button, index) => {
        const item = items[index];
        button.hidden = !((category === "All" || category === item.category || category === "Recent" && recent.includes(index)) && `${item.label} ${item.keywords || ""} ${item.emoji}`.toLocaleLowerCase().includes(query));
        button.textContent = symbol(item); button.setAttribute("aria-pressed", String(select.value === symbol(item))); button.tabIndex = -1;
      });
      visible = buttons.filter((button) => !button.hidden); if (visible[0]) visible[0].tabIndex = 0;
      categories.forEach((button) => { button.setAttribute("aria-pressed", String(button.dataset.emojiCategory === category)); if (button.dataset.emojiCategory === "Recent") button.disabled = !recent.length; });
      status.textContent = `${visible.length} ${visible.length === 1 ? "emoji" : "emoji"} found${query ? ` for ${search.value.trim()}` : ""}.`;
    };
    const choose = (index: number) => {
      const item = items[index], emoji = symbol(item);
      if (!Array.from(select.options).some((option) => option.value === emoji)) { const option = new Option(`${emoji} ${item.label}`, emoji); select.add(option); }
      select.value = emoji; recent = [index, ...recent.filter((value) => value !== index)].slice(0, 12); render();
      select.dispatchEvent(new Event("input", { bubbles: true })); select.dispatchEvent(new Event("change", { bubbles: true }));
      status.textContent = `${item.label} selected.`;
      root.dispatchEvent(new CustomEvent("haze:emoji-select", { bubbles: true, detail: { emoji, label: item.label, category: item.category } }));
    };
    buttons.forEach((button, index) => button.addEventListener("click", () => choose(index)));
    categories.forEach((button) => button.addEventListener("click", () => { category = button.dataset.emojiCategory!; render(); }));
    search.addEventListener("input", render); tone.addEventListener("change", render);
    search.addEventListener("keydown", (event) => { if (event.key === "ArrowDown" && visible[0]) { event.preventDefault(); visible[0].focus(); } if (event.key === "Escape" && search.value) { event.preventDefault(); event.stopPropagation(); search.value = ""; render(); } });
    grid.addEventListener("keydown", (event) => {
      const current = visible.indexOf(event.target as HTMLButtonElement); if (current < 0) return;
      const columns = Math.max(1, Math.round(grid.clientWidth / Math.max(1, visible[0].getBoundingClientRect().width + 4)));
      let next = current;
      if (event.key === "ArrowRight") next++; else if (event.key === "ArrowLeft") next--; else if (event.key === "ArrowDown") next += columns; else if (event.key === "ArrowUp") next -= columns; else if (event.key === "Home") next = 0; else if (event.key === "End") next = visible.length - 1; else return;
      event.preventDefault(); const target = visible[Math.max(0, Math.min(visible.length - 1, next))]; visible.forEach((button) => button.tabIndex = button === target ? 0 : -1); target.focus();
    });
    select.addEventListener("change", () => { buttons.forEach((button, index) => button.setAttribute("aria-pressed", String(select.value === symbol(items[index])))); });
    root.form?.addEventListener("reset", () => queueMicrotask(() => { search.value = ""; category = "All"; tone.value = "0"; render(); }));
    root.querySelector<HTMLElement>("[data-emoji-tools]")!.hidden = false;
    root.setAttribute("data-enhanced", ""); render();
  }
  const init = () => document.querySelectorAll<HTMLFieldSetElement>("[data-haze-emoji-picker]").forEach(enhance);
  init();
  if (!document.documentElement.hasAttribute("data-haze-emoji-picker-listener")) {
    document.documentElement.setAttribute("data-haze-emoji-picker-listener", "");
    document.addEventListener("astro:page-load", init);
  }
</script>
```
