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.jsonpnpm dlx shadcn@latest add https://panelui.dev/r/web/emoji-picker.jsonyarn dlx shadcn@latest add https://panelui.dev/r/web/emoji-picker.jsonbunx shadcn@latest add https://panelui.dev/r/web/emoji-picker.jsonThe 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.sideandalignplace it, andoverputs 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. ATriggeras 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 aContentwithover.
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
| Prop | Type | Default | Description |
|---|---|---|---|
onSelect | (choice: EmojiChoice) => void | â | Called with the emoji and its name when one is chosen. The picker stays open. |
categories | readonly EmojiCategory[] | â | The emoji to offer, by category. Default Unicode's, with English names. |
tone | number | â | The skin tone, from 0 for none to 5, when the caller holds it. |
defaultTone | number | 0 | The 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. |
recents | readonly string[] | â | The emoji used lately, newest first, when the caller holds them. They come first. |
defaultRecents | readonly 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
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | â |
EmojiPicker.Content
| Prop | Type | Default | Description |
|---|---|---|---|
side | Popover.Positioner.Props['side'] | 'top' | Which side of the trigger it opens on. Default top. |
align | Popover.Positioner.Props['align'] | 'end' | How it lines up with the trigger along that side. Default end. |
sideOffset | number | 10 | The gap between the trigger and the picker, in pixels. Default 10. |
over | boolean | false | Puts it over the trigger, middle on middle, as a Dial wants. Default false. |
container | Popover.Portal.Props['container'] | â | Where in the document it is put. Default document.body. |
className | string | â |
EmojiPicker.Sphere
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 232 | How wide the sphere is, in pixels, without what is round it. Default 232. |
placeholder | string | 'Search' | What the search says while empty. Default "Search". |
showCategories | boolean | true | Whether the categories are round its trailing side. Default true. |
showTones | boolean | true | Whether the skin tones are round its lower corner. Default true. |
EmojiPicker.Fan
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 232 | How wide it is, in pixels. It is a little over half as tall. Default 344. |
placeholder | string | 'Search' | What the search says while empty. Default "Search". |
EmojiPicker.Panel
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | 'Search emojiâĶ' | What the search says while empty. Default "Search emojiâĶ". |
emptyText | ReactNode | 'No emoji match' | What the list says when nothing matches. Default "No emoji match". |
EmojiPicker.Reactions
| Prop | Type | Default | Description |
|---|---|---|---|
emojis | readonly string[] | ['ð', 'âĪïļ', 'ð', 'ð', 'ðŪ'] | The usual few. Default ð âĪïļ ð ð ðŪ. |
value | readonly string[] | [] | Which are on, drawn as pressed. |
EmojiPicker.Dial
| Prop | Type | Default | Description |
|---|---|---|---|
emojis | readonly string[] | ['ð', 'âĪïļ', 'ð', 'ð', 'ðŪ'] | The emoji in the ring, from the top round clockwise. Six to ten read best. |
size | number | 232 | The ring's width, in pixels. Default 216. |
hint | ReactNode | â | 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"