Emoji picker
ProA panel for choosing emoji, with search, a tab per category, recently used emoji and a skin tone; plus its trigger, which inserts at the caret of a message field and opens in a popover, a bottom sheet or docked in the keyboard’s place on phones; and createEmojiSuggestions, which suggests emoji after : in a message field. Not an M3 component (@windmorph/react-pro/emoji-picker, with emojibase-data).
import { EmojiPicker, EmojiPickerTrigger, useEmojiPickerStorage } from '@windmorph/react-pro/emoji-picker';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
A panel for choosing emoji: a search box, a tab per category, a grid of every emoji the device can draw, a preview with the focused emoji's name, and a skin tone. M3 has no emoji picker, so it is drawn with M3's surfaces, tabs, menus and type.
EmojiPickerTrigger: an emoji button in a message field's tools, or beside any text box. It opens the picker, and inside aMessageFieldorRichMessageFieldeach pick goes in at the caret through the field'sinsertText(insert={false}turns it off).EmojiPicker: the panel alone, placed by the app (a side panel, a settings page, a status).- The category tabs are M3's secondary tabs by default;
tabsVariant="primary"draws primary tabs, on the picker or the trigger. - For a short, fixed row of reactions to a message, use a
ReactionPickerinstead.
Import it from @windmorph/react-pro/emoji-picker, with emojibase-data and emojibase installed (pnpm add emojibase-data emojibase): its default loader imports the data, so bundlers need the package even when you pass your own. Pro's main entry never reaches the data.
Where it shows
The trigger's presentation picks the form, decided as it opens, so a rotation or a resize while it's open keeps the picker, its search and its focus:
popover: inside a message field, against the whole field, above it (below where there's no room) and aligned to the side the button is on, so it never covers the text being written; elsewhere,top-startof the button.placementchanges the side,anchorRefplaces it against an element of yours (a composer you lay out yourself), and its height follows the window. Beside a field it isn't modal: the field stays usable, a press in it keeps the picker open, and a press or focus elsewhere closes it.sheet: a modal bottom sheet with a drag handle, at most--wm-emoji-picker-sheet-height, with its search and tabs at the top and its footer at the bottom.docked: in the message field it's in, with nothing dimmed, so each pick shows in the text as it goes in.dockedPlacementsays where:below: in the keyboard's place, as messaging apps do on phones. The on-screen keyboard closes and the panel takes its height, so the field stays where it was. The emoji button becomes a keyboard button (“Show keyboard”) that puts the caret back in the text, and a press in the text goes back to typing too.above: above the field, taking the room of the conversation above it, so the field stays where it was. The button keeps its emoji icon and is named “Hide emoji” (labels.hide). Lay the conversation out to give the room up: in a flex column, the scrolling list above the field asflex: 1withmin-height: 0, pinned to its end so the last messages stay in sight.auto(the default): above from the medium window size, where there's no on-screen keyboard to replace, below it under that.
auto(the default): the popover from the medium window size or with a fine pointer; below it by touch, docked inside a message field and a sheet anywhere else.dockedoutside a message field falls back to the sheet.
A pick keeps the picker open for more; Escape or a press outside closes it, and closeOnSelect closes it on the first pick. Inside a message field, focusOnSelect says where focus goes after a pick: auto (the default) puts a mouse or pen pick back in the text, the caret after the emoji, so the next keys typed carry on the message, keeps a keyboard pick on the emoji picked, and leaves a touch where it was, so the on-screen keyboard stays down; picker always stays in the picker and field always goes back to the text. In the sheet focus stays in the sheet. The trigger's button renders on the server; the panel's code and the data load on the button's first hover, focus or press, so a closed trigger costs little.
Docked: height and motion
- Below the field, the panel never moves the field. With the on-screen keyboard up, it takes the keyboard's place at the keyboard's height, read as it swaps in, with no slide. With no keyboard up, it rises from the field's edge on the default spatial spring's duration with the effects easing, which never overshoots, so the height never bounces; closing is the reverse. Going back to typing, it holds its height until the keyboard has settled over it, and if no keyboard comes it slides down as on any other close. A motion interrupted part-way (the button pressed again mid-rise) turns back smoothly from where it is.
- The keyboard's height is remembered for the page's session, never stored. Before any keyboard has been measured the panel is 40% of the window, at most
20rem;defaultKeyboardHeightgives it a height in px instead (one the app kept), andonKeyboardHeightChange(height)is called each time a new one is measured, so the app can keep it for the next visit. A--wm-emoji-picker-docked-heightyou set wins over both. - Below the field on a phone, the panel takes the keyboard's place on the screen: it reaches the window's sides and foot whatever the field's own inset (stopping at a container that clips or scrolls), with the field's container colour, its grown corner on top and its outline, 8px under the field, and its search box a tone off it. With a mouse on a computer, a panel docked below keeps the field's width.
- Above the field (from the medium window size), the panel is part of the field: the field's container colour, grown corner and outline, 8px above it, its search box a tone off the panel. It opens and closes as the field's own rows do, its height on the field's spring with a fade, and the field stays exactly where it was. On a field with another container colour, set
--wm-emoji-picker-docked-above-search-container-colora step from it. - The
docked-*tokens time the panel below the field (docked-duration,docked-easing,docked-fade-duration,docked-fade-easing); thedocked-below-*tokens draw it (docked-below-container-color,docked-below-container-shape,docked-below-search-container-color,docked-below-outline-color,docked-below-gap) and thedocked-above-*tokens the panel above it (docked-above-container-color,docked-above-container-shape,docked-above-search-container-color,docked-above-outline-color,docked-above-gap). Your owncontainer-colorandsearch-container-colorwin over the field's colours, and thedocked-below-*anddocked-above-*ones over both. - Under reduced motion the height changes at once in both places and only the fades run.
Suggestions while typing
createEmojiSuggestions(options) builds the source a MessageField or RichMessageField takes as emojiSuggestions: : and two letters (:sm) list matching emoji, and Enter, Tab or a press puts one in place of what was typed. The fields hold the trigger rules, keys and list (see Message field's Suggestions while typing); this entry holds the data, so a field without it never loads any. Build it once, at module level or in a useMemo, not on every render.
loadDataandlocaleload the data as the picker's do, on the first:typed, from your own bundle. A load that fails is given back for a few seconds, then the next:tries again.loadShortcodes: the shortcodes the list shows and matches (:smile:), by hexcode. Emojibase's own English ones by default with the default data (defaultShortcodesLoader), none with your ownloadData; pass any ofemojibase-data's presets, your own, ornullfor none (names and keywords still match).customandcustomText: your own emoji, matched by id and name, as in the picker.minChars(2) characters after:open the list, andmaxItems(10) caps it. WithreplaceOnColon(on), a:typed right after an exact shortcode (:smile:) turns it into the emoji. Withemoticons(off), an emoticon followed by a space becomes its emoji (:)🙂,;)😉,<3❤️). In aMessageField, undo gives back what was typed.- The list ranks an exact shortcode first, the recently used ones that match next (newest first), then shortcodes and names that start with what's typed, then a word of the name or a keyword.
storageKey("wm-emoji-picker") is the picker's: pass the same one as yourEmojiPickerTrigger, so the suggestions rank its Recently used first, take its skin tone and add their picks to it. classNamesreaches the list's parts, and the list's tokens are the Message field page's suggestion list tokens; its words are the field'semojiSuggestions,emojiLoadingandemojiResultslabels.
Data and languages
- The emoji, their names and their search words come from
emojibase-data, loaded on first open from your own bundle, never from a third-party server, and kept for the page bylocale. The default is English. The names and keywords are Unicode CLDR's, under the Unicode License v3: credit them where your app lists its licences. - For another language, pass that language's data and a
localeto keep it under:locale="de" loadData={() => import('emojibase-data/de/data.json')}. Search then matches that language's names and keywords. Translate the picker's own words withlabels, or once for the app with aLabelsProviderunder itsEmojiPickerkey. - Every word of a search must appear in an emoji's name or a keyword, anywhere in it (so languages written without spaces search too), ignoring case and accents.
- Emoji the device's font can't draw are hidden, found once per page by drawing a sample of each Unicode version; where flags draw as two letters, the country flags are hidden. Nothing about the device is stored.
- Glyphs are the platform's colour emoji font (
--wm-emoji-picker-font-family).renderEmojidraws your own image set instead.
Custom and animated emoji
custom adds your own emoji ({ id, label, tags, src, animatedSrc, render }) in a Custom category after Recently used, found by search and kept in Recently used. A text box can't hold an image, so a pick hands text for it, :id: unless customText says otherwise, with the emoji itself in custom; draw its image wherever you show that text. src is drawn lazily; animatedSrc (GIF, WebP, APNG) plays only while the emoji is hovered or focused and in the preview, and never under reduced motion, so the grid stays still. An image that fails to load falls back: a failed animatedSrc to src, and a failed src to the label's first letter on a circle, the cell keeping its name.
Recently used and skin tone
- Recently used holds the last
maxRecentpicks (16), newest first. A pick is recorded at once, but the row keeps its order until the picker opens again, so repeated presses never land on a moved emoji. - One skin tone applies to the whole picker, chosen from the menu in its footer (opening from the button's end, so it stays over the picker); an emoji of two people takes its same-tone form.
- Both are kept in
localStorageunderstorageKey("wm-emoji-picker";nullkeeps them in memory), and blocked or full storage never throws. Everyone using the browser shares the key, so an app with accounts passes one per account, or controls them withrecent/onRecentChangeandskinTone/onSkinToneChange. useEmojiPickerStorage(storageKey)reads and writes the same stored list and tone, for an app that shows recently used emoji elsewhere.EMOJI_CATEGORIESandEMOJI_SKIN_TONESlist the categories and tones, for your own labels.
When not to use
For a short, fixed row of reactions to a message, use a Reaction picker; for one-tap choices from a few options, chips or a Menu.
See also
- Message field: A rounded field for writing something to send (a comment, a reply, a chat message) that grows from a pill into a box, with a send button, tools that open into their own row on focus, a reply banner, attachments and suggestions while typing (people after @, tags after #, emoji after :); plus its trigger. Not an M3 component (@windmorph/react-pro).
- Rich message field: A message field that formats as you type, with markers in plain text: bold, italic, strike, code, links, lists, quotes and code blocks, with a formatting toolbar, and suggestions while typing (@mentions of people, #tags and emoji after :); plus FormattedText, which shows what it wrote. Not an M3 component (@windmorph/react-pro/rich-text, with Tiptap).
- Reaction picker: A reaction button that likes on tap, with a floating row of reactions on long press, hover or the keyboard; slide a finger along it to pick. Not an M3 component (@windmorph/react-pro).