Components

Emoji Picker

A searchable grid of every emoji, grouped and laid out as on iOS and macOS, with one skin tone for all of them.

Usage

import { EmojiPicker } from 'nyctoui/emoji-picker'

<EmojiPicker onEmojiSelect={({ emoji }) => insert(emoji)} />

With no children the picker renders all of its parts: a search field, the skin tone, the grid and the category bar. It is a panel, not a popup, so it works on a page, in a Popover or in a Dropdown submenu. Close the popup yourself in onEmojiSelect.

Focus stays in the search field. The arrow keys move through the grid and Enter picks the lit emoji; while searching, the first result is lit, so typing a word and pressing Enter is enough.

Good for

  • Reactions on a message in a team chat app.
  • Inserting an emoji into a comment or a post composer.
  • Choosing a page or channel icon in a notes or chat app.
  • Adding a status emoji to a user profile.

Loading

The emoji data is not in your bundle. It is a separate chunk of about 42 KB gzipped, fetched the first time a picker mounts and kept in memory after that, so later opens render at once. To skip the first wait, call preloadEmojiData() when the trigger is hovered or focused, as the demo above does.

The grid is virtualized with TanStack Virtual: only the rows in view, plus four either side, are in the DOM, so the picker opens and scrolls at the same speed with two thousand emojis as with ten. On load it checks which emoji version the platform can draw and leaves out newer ones, so nobody sees empty boxes. Flags are left out where the system font has none, as on Windows.

The data comes from emojibase-data. After upgrading it, run pnpm emoji-data to regenerate the table.

Anatomy

<EmojiPicker>
  <EmojiPickerHeader>
    <EmojiPickerSearch />
    <EmojiPickerSkinTone />
  </EmojiPickerHeader>
  <EmojiPickerList />
  <EmojiPickerCategories />
  <EmojiPickerPreview />
</EmojiPicker>

Examples

Standalone

On a page, give the picker a surface through sx. It is 300px wide at the default nine columns and 380px tall.

In a popover

Put it in a PopoverContent with no padding, and control open to close it on a pick. Here the trigger shows the chosen emoji.

In a submenu

Pass bare to the DropdownSubContent so the menu’s padded list does not wrap the picker. The picker keeps the menu’s typeahead and arrow keys to itself; Escape still closes the menu.

Inserting into text

Remember the caret before focus moves into the picker, insert at it, then put focus back. Hold Shift to insert several emojis without closing; onEmojiSelect passes the event to tell.

Composition

Pass parts as children to drop or rearrange them. This one has no skin tone, no recents and no category bar, and a preview footer that names the emoji under the pointer.

Skin tone

The tone applies to every emoji that takes one. Uncontrolled, the last tone picked is remembered in localStorage. Control it with skinTone to keep it somewhere else, such as the user’s profile.

Best practices

Do
  • Open it from a button beside the field or the message, in a popover or a submenu.
  • Keep the search field first, since most people type a word rather than scroll.
  • Pass recents so the emoji people use most are at the top.
  • Insert at the caret and give focus back to the field after a pick.
Don’t
  • Leave it always open on a page where emoji are an occasional extra.
  • Load the emoji data up front on pages that rarely need it. Load it when the picker is about to open.

API reference

EmojiPicker

Loads the data and holds the search, the tone and the lit emoji. Renders a <div>.

PropTypeDefault
onEmojiSelect
Called with { emoji, label, skinTone } when an emoji is picked by click or Enter.
(emoji: EmojiPickerEmoji, event) => void—
skinTone
The tone, from default yellow (0) to dark (5). For controlled use.
0 | 1 | 2 | 3 | 4 | 5—
defaultSkinTone
Starting tone. A tone the user picked before wins over it.
0 | 1 | 2 | 3 | 4 | 50
onSkinToneChange
Called when the user picks a tone.
(tone: SkinTone) => void—
columns
Emojis per row. Each column is 32px.
number9
recents
Shows the 18 emojis picked last, kept in localStorage.
booleantrue
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerHeader

The row along the top. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerSearch

Filters by name and tag. Renders an <input>.

PropTypeDefault
placeholder
Placeholder text.
string'Search emoji'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerSkinTone

A hand in the current tone that fans out the six tones. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerList

The grid, virtualized with TanStack Virtual, with a pinned section heading. Renders a <div>.

PropTypeDefault
empty
Shown when a search matches nothing.
ReactNode'No emoji found'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerCategories

The bar of category buttons along the bottom. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

EmojiPickerPreview

The lit emoji and its name. Renders a <div>.

PropTypeDefault
children
Shown when no emoji is lit.
ReactNode'Pick an emoji…'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

preloadEmojiData

A function. Starts loading the data and returns a promise; safe to call any number of times.