Emoji Picker

Every emoji on a sphere that turns under the hand, with its search bent round it.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerOverview() {
  const [text, setText] = useState('');
  return (
    <div className="flex w-full max-w-sm flex-col items-center gap-3">
      <EmojiPicker onSelect={({ emoji }) => setText((value) => value + emoji)}>
        <EmojiPicker.Sphere />
        <EmojiPicker.Field
          aria-label="Message"
          placeholder="Message"
          value={text}
          onChange={(event) => setText(event.target.value)}
        />
      </EmojiPicker>
    </div>
  );
}

Use it to add an emoji to a message, a reaction to a post or an icon to a page. All of them are on a sphere: drag it, wheel it or use the arrow keys to turn it, and press one to choose it. The picker stays open, so several can be added.

Typing searches by name and by a few other words for each. The rest dim, the sphere turns to the first match, and the search says which match it is on.

It needs a square of about 340 pixels. Where there is less height, use EmojiPicker.Fan; where there is less of both, EmojiPicker.Reactions.

The emoji are drawn by the reader's own system, so they look as that system draws them.

Installation

npx shadcn@latest add https://panelui.dev/r/web/emoji-picker.json

The source is copied into components/panelui/, where you can edit it.

Usage

import { EmojiPicker } from "@/components/panelui/emoji-picker"
<EmojiPicker onSelect={({ emoji }) => setText(text + emoji)}>
  <EmojiPicker.Field value={text} onChange={(event) => setText(event.target.value)} placeholder="Message">
    <EmojiPicker.Trigger />
  </EmojiPicker.Field>
  <EmojiPicker.Content>
    <EmojiPicker.Sphere />
  </EmojiPicker.Content>
</EmojiPicker>

Composition

<EmojiPicker>
  <EmojiPicker.Field>
    <EmojiPicker.Trigger />
  </EmojiPicker.Field>
  <EmojiPicker.Content>
    <EmojiPicker.Sphere />
  </EmojiPicker.Content>
</EmojiPicker>

<EmojiPicker>
  <EmojiPicker.Reactions>
    <EmojiPicker.Trigger />
  </EmojiPicker.Reactions>
  <EmojiPicker.Content>
    <EmojiPicker.Panel />
  </EmojiPicker.Content>
</EmojiPicker>
  • EmojiPicker.Field — A line to write in, with the trigger at its end. It takes an input's props. A chosen emoji flies to the trigger, or into the field when there is none.
  • EmojiPicker.Trigger — The button that opens the picker: a face, or what it is given.
  • EmojiPicker.Content — The layer the picker is in, which draws nothing of its own. side and align place it, and over puts it middle on middle over the trigger.
  • EmojiPicker.Sphere — Every emoji on a sphere, with the search, the categories, the skin tones and the name of the one pointed at on circles round it. It can be put straight on a page, without a trigger.
  • EmojiPicker.Fan — Every emoji on half a wheel of three rings, rising out of a search bar. It is a little over half as tall as it is wide.
  • EmojiPicker.Panel — A grid under category headings, with a search, a row of categories, and the name of the one pointed at.
  • EmojiPicker.Reactions — A row of the usual few, each growing as the pointer nears it. A Trigger as its child leads to the rest.
  • EmojiPicker.Dial — A few emoji in a ring, chosen by the pointer's direction from the middle. Put it in a Content with over.

Examples

From a field

A Trigger in the field opens the sphere over the page in a Content. It stays open while emoji are added, and closes on Escape or a press outside.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerInField() {
  const [text, setText] = useState('');
  return (
    <div className="w-full max-w-sm">
      <EmojiPicker onSelect={({ emoji }) => setText((value) => value + emoji)}>
        <EmojiPicker.Field
          aria-label="Message"
          placeholder="Message"
          value={text}
          onChange={(event) => setText(event.target.value)}
        >
          <EmojiPicker.Trigger />
        </EmojiPicker.Field>
        <EmojiPicker.Content>
          <EmojiPicker.Sphere />
        </EmojiPicker.Content>
      </EmojiPicker>
    </div>
  );
}

Fan

EmojiPicker.Fan is the same emoji on half a wheel, for where there is less height: above a keyboard, or at the foot of a panel. Drag it round like a dial, or wheel it. The categories are round its hub, and the emoji pointed at shows in the middle.

Typing leaves only the matches on the wheel. The hand at the end of the bar steps through the skin tones.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerFan() {
  const [text, setText] = useState('');
  return (
    <div className="flex w-full max-w-sm flex-col items-center gap-4">
      <EmojiPicker onSelect={({ emoji }) => setText((value) => value + emoji)}>
        <EmojiPicker.Field
          aria-label="Message"
          placeholder="Message"
          value={text}
          onChange={(event) => setText(event.target.value)}
        />
        <EmojiPicker.Fan size={320} />
      </EmojiPicker>
    </div>
  );
}

Used lately

defaultRecents puts the emoji used lately first, so they are what the sphere opens on. recents with onRecentsChange keeps them in a user's settings.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerRecent() {
  const [last, setLast] = useState('');
  return (
    <div className="flex flex-col items-center gap-2">
      <EmojiPicker
        onSelect={({ emoji, name }) => setLast(`${emoji} ${name}`)}
        defaultRecents={['🍉', 'ðŸšē', '👋', '🎧', 'ðŸŠī']}
      >
        <EmojiPicker.Sphere />
      </EmojiPicker>
      <p className="h-5 text-sm text-muted-foreground">{last ? `Chosen: ${last}` : 'Turn it and press one'}</p>
    </div>
  );
}

Panel

EmojiPicker.Panel is a grid for places that want a list: here, choosing a page's icon. The arrow keys move through it and Enter chooses.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerPanel() {
  const [icon, setIcon] = useState('ðŸŠī');
  return (
    <EmojiPicker onSelect={({ emoji }) => setIcon(emoji)}>
      <EmojiPicker.Trigger className="size-14 rounded-2xl border text-3xl" aria-label={`Icon: ${icon}`}>
        {icon}
      </EmojiPicker.Trigger>
      <EmojiPicker.Content side="bottom" align="center">
        <EmojiPicker.Panel />
      </EmojiPicker.Content>
    </EmojiPicker>
  );
}

Reactions

EmojiPicker.Reactions shows the usual few. value draws the ones already given as pressed, and choosing one again can take it back. The plus opens the rest.

'use client';

import { PlusSignIcon } from '@hugeicons/core-free-icons';
import { HugeiconsIcon } from '@hugeicons/react';
import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

export default function EmojiPickerReactions() {
  const [given, setGiven] = useState<string[]>(['🎉']);
  return (
    <div className="flex flex-col items-center gap-4">
      <EmojiPicker
        onSelect={({ emoji }) =>
          setGiven((list) => (list.includes(emoji) ? list.filter((each) => each !== emoji) : [...list, emoji]))
        }
      >
        <EmojiPicker.Reactions value={given}>
          <EmojiPicker.Trigger aria-label="More emoji" className="size-10">
            <HugeiconsIcon icon={PlusSignIcon} />
          </EmojiPicker.Trigger>
        </EmojiPicker.Reactions>
        <EmojiPicker.Content side="top" align="center">
          <EmojiPicker.Sphere size={208} />
        </EmojiPicker.Content>
      </EmojiPicker>
      <p className="h-6 text-lg">{given.join(' ')}</p>
    </div>
  );
}

Dial

EmojiPicker.Dial opens over its button. Move the pointer towards one and press: the direction chooses, so nothing has to be aimed at. Use it for six to ten that stay the same.

'use client';

import { useState } from 'react';
import { EmojiPicker } from '@/components/panelui/emoji-picker';

const MOODS = ['😀', '😍', 'ðŸĪ”', 'ðŸ˜Ū', 'ðŸ˜Ē', 'ðŸ˜Ą', 'ðŸĨą', 'ðŸĨģ'];

export default function EmojiPickerDial() {
  const [mood, setMood] = useState('🙂');
  const [open, setOpen] = useState(false);
  return (
    <EmojiPicker
      open={open}
      onOpenChange={setOpen}
      onSelect={({ emoji }) => {
        setMood(emoji);
        setOpen(false);
      }}
    >
      <EmojiPicker.Trigger className="size-14 bg-muted text-2xl" aria-label={`Mood: ${mood}`}>
        {mood}
      </EmojiPicker.Trigger>
      <EmojiPicker.Content over>
        <EmojiPicker.Dial emojis={MOODS} hint="How was it?" />
      </EmojiPicker.Content>
    </EmojiPicker>
  );
}

Your own set

categories replaces the emoji with your own, by category, each with a name and the words to find it by. A short list wraps round the sphere more than once.

'use client';

import { useState } from 'react';
import { EmojiPicker, type EmojiCategory } from '@/components/panelui/emoji-picker';

const CATEGORIES: EmojiCategory[] = [
  {
    value: 'sky',
    label: 'Sky',
    icon: '⛅',
    emojis: [
      '☀ïļ sun',
      'ðŸŒĪïļ mostly sunny',
      '⛅ part cloud',
      'ðŸŒĶïļ showers',
      '🌧ïļ rain',
      '⛈ïļ storm',
      'ðŸŒĐïļ lightning',
      'ðŸŒĻïļ snow',
      '🌊ïļ tornado',
      'ðŸŒŦïļ fog',
      '🌈 rainbow',
      '☔ umbrella',
    ].map(entry),
  },
  {
    value: 'garden',
    label: 'Garden',
    icon: '🌷',
    emojis: [
      'ðŸŒą seedling',
      'ðŸŠī potted plant',
      '🌷 tulip',
      'ðŸŒŧ sunflower',
      '🌞 blossom',
      'ðŸŒđ rose',
      'ðŸŒŋ herb',
      '🍀 clover',
      'ðŸŒĩ cactus',
      '🍄 mushroom',
      '🐝 bee',
      'ðŸĶ‹ butterfly',
      '🐞 ladybird',
      '🐌 snail',
    ].map(entry),
  },
  {
    value: 'harvest',
    label: 'Harvest',
    icon: '🍓',
    emojis: [
      '🍓 strawberry',
      '🍅 tomato',
      'ðŸĨ• carrot',
      'ðŸŒ― maize',
      'ðŸŦ‘ pepper',
      'ðŸĨ’ cucumber',
      'ðŸĨŽ greens',
      '🧅 onion',
      'ðŸĨ” potato',
      '🍎 apple',
      '🍐 pear',
      '🍑 peach',
      '🍒 cherries',
      '🎃 pumpkin',
    ].map(entry),
  },
];

function entry(line: string) {
  const [emoji, ...name] = line.split(' ');
  return { emoji: emoji!, name: name.join(' ') };
}

export default function EmojiPickerCustom() {
  const [last, setLast] = useState('');
  return (
    <div className="flex flex-col items-center gap-2">
      <EmojiPicker categories={CATEGORIES} onSelect={({ emoji, name }) => setLast(`${emoji} ${name}`)}>
        <EmojiPicker.Sphere showTones={false} placeholder="Garden" />
      </EmojiPicker>
      <p className="h-5 text-sm text-muted-foreground">{last ? `Chosen: ${last}` : ''}</p>
    </div>
  );
}

API Reference

EmojiPicker

PropTypeDefaultDescription
onSelect(choice: EmojiChoice) => void—Called with the emoji and its name when one is chosen. The picker stays open.
categoriesreadonly EmojiCategory[]—The emoji to offer, by category. Default Unicode's, with English names.
tonenumber—The skin tone, from 0 for none to 5, when the caller holds it.
defaultTonenumber0The skin tone to begin with, when the caller does not hold it. Default 0.
onToneChange(tone: number) => void—Called with the skin tone when another is chosen.
recentsreadonly string[]—The emoji used lately, newest first, when the caller holds them. They come first.
defaultRecentsreadonly string[][]The emoji used lately to begin with.
onRecentsChange(recents: string[]) => void—Called with the emoji used lately, newest first, when one is chosen.

EmojiPicker.Trigger

PropTypeDefaultDescription
classNamestring—

EmojiPicker.Content

PropTypeDefaultDescription
sidePopover.Positioner.Props['side']'top'Which side of the trigger it opens on. Default top.
alignPopover.Positioner.Props['align']'end'How it lines up with the trigger along that side. Default end.
sideOffsetnumber10The gap between the trigger and the picker, in pixels. Default 10.
overbooleanfalsePuts it over the trigger, middle on middle, as a Dial wants. Default false.
containerPopover.Portal.Props['container']—Where in the document it is put. Default document.body.
classNamestring—

EmojiPicker.Sphere

PropTypeDefaultDescription
sizenumber232How wide the sphere is, in pixels, without what is round it. Default 232.
placeholderstring'Search'What the search says while empty. Default "Search".
showCategoriesbooleantrueWhether the categories are round its trailing side. Default true.
showTonesbooleantrueWhether the skin tones are round its lower corner. Default true.

EmojiPicker.Fan

PropTypeDefaultDescription
sizenumber232How wide it is, in pixels. It is a little over half as tall. Default 344.
placeholderstring'Search'What the search says while empty. Default "Search".

EmojiPicker.Panel

PropTypeDefaultDescription
placeholderstring'Search emojiâ€Ķ'What the search says while empty. Default "Search emojiâ€Ķ".
emptyTextReactNode'No emoji match'What the list says when nothing matches. Default "No emoji match".

EmojiPicker.Reactions

PropTypeDefaultDescription
emojisreadonly string[]['👍', 'âĪïļ', '😂', '🎉', 'ðŸ˜Ū']The usual few. Default 👍 âĪïļ ðŸ˜‚ 🎉 ðŸ˜Ū.
valuereadonly string[][]Which are on, drawn as pressed.

EmojiPicker.Dial

PropTypeDefaultDescription
emojisreadonly string[]['👍', 'âĪïļ', '😂', '🎉', 'ðŸ˜Ū']The emoji in the ring, from the top round clockwise. Six to ten read best.
sizenumber232The ring's width, in pixels. Default 216.
hintReactNode—What its middle says before one is pointed at. Default "Pick one".

Every part also takes the props of the element it renders, and a className.

Notes

Keyboard

The search has focus when the picker opens. With nothing typed, the arrow keys move over the sphere and Enter chooses. With something typed, the up and down arrows step through the matches. The first Escape clears the search and the next closes the picker.

Accessibility

The search is a combobox for a listbox of emoji, and the one under the highlight is announced by its name. The categories are a toolbar and the skin tones a radio group.

What is drawn

The sphere draws the emoji facing the reader and no others, about a hundred however many there are. The panel holds every emoji in the page and leaves the ones out of view undrawn.

The emoji

The set is Unicode's, up to Emoji 15.0, one per person rather than one per gender. Skin tones apply to the emoji that take them, and to the ones used lately. The names and words are English; pass categories for another language.

Reduced motion

With reduced motion turned on, the sphere goes straight to where it is turned, and a chosen emoji does not fly.

Server Components

EmojiPicker is a client component. In a file that starts with "use client", write its parts with a dot, as on this page. A Server Component cannot read EmojiPicker.Field off the import, so each part is also exported by name: EmojiPickerField is EmojiPicker.Field, and so on for the others.

import { EmojiPicker, EmojiPickerField, EmojiPickerTrigger, EmojiPickerContent, EmojiPickerSphere, EmojiPickerFan, EmojiPickerPanel, EmojiPickerReactions, EmojiPickerDial } from "@/components/panelui/emoji-picker"

On this page