Lightweight Emoji Picker with Search – Faceclick
The library provides keyword search capabilities using Unicode specification tags and organizes emojis into browsable groups for easy navigation.
1. Add Faceclick’s JavaScript and CSS files to the webpage.
<script src="faceclick.js"></script> <link rel="stylesheet" href="faceclick.css">
2. Attach the emoji picker to the text field you specify.
<textarea id="example"></textarea> <button id="trigger">Toggle the emoji picker</button>
var button = document.getElementById('trigger');
var textarea = document.getElementById('example');
FC.attach(button, textarea); 3. For more control over emoji selection, use attach_cb() to define custom behavior when users pick an emoji:
FC.attach_cb(button, function(emoji) {
FC.close();
// Custom handling - append to div, send to API, etc.
document.getElementById('output').textContent += emoji;
}); 4. You can change the default settings after the library has loaded to control the picker’s behavior.
FC.group_clears_search: When true (default), the search box is cleared when a user clicks a group tab.FC.search_clears_group: When true (default), the group tab selection is cleared when a user types in the search box.FC.close_on_clickaway: When true (default), the popup closes if the user clicks anywhere outside of it.FC.close_on_pick: When true (default), the popup closes after an emoji is selected, and focus returns to the text input.5. More API methods.
FC.attach_popup(element, callback): A lower-level function that opens the popup next to a given element and calls your callback upon selection.FC.popup(x, y, callback): The lowest-level method. It opens the picker at specific screen coordinates (x, y) and executes the callback with the selected emoji.FC.insert(element, insert_txt): A utility method that inserts text into a text input at the current cursor position. FC.attach() uses this internally.FC.close(): Manually closes the emoji picker popup.Q: How do I customize the popup positioning?
A: Use FC.popup(x, y, callback) for full control over coordinates. The attach_popup() method positions the picker to the right of the target element by default using getBoundingClientRect().right + 5 for x and .top for y. You can calculate your own coordinates based on element dimensions and pass them to popup() directly.
Q: Does Faceclick work with contenteditable divs?
A: The FC.insert() method specifically uses setRangeText(), which only works on input and textarea elements. For contenteditable divs, use attach_cb() with a custom callback that manipulates the Selection API. You’ll need to get the current range, create a text node with the emoji, and insert it at the cursor position manually.
Q: How do I style the picker to match my site’s design?
A: The CSS file uses simple class and ID selectors (#fc_popup, #fc_filters, #fc_list_scrollbox). Override these in your own stylesheet to change colors, borders, shadows, and dimensions. The popup uses absolute positioning, so you can adjust z-index if it conflicts with other elements.
Q: Does the search support fuzzy matching or typos?
A: Search uses simple substring matching with indexOf(). The search text must appear exactly within the emoji’s tags or label. This keeps the code minimal but means typos won’t return results. The Unicode tags are comprehensive enough that most reasonable keywords will match something, but exact spelling matters.
The post Lightweight Emoji Picker with Search – Faceclick appeared first on CSS Script.
Warhammer 40,000: Mechanicus II launches on May 21 — alongside the Warhammer Skulls video game…
Former Nintendo staff have branded the recent leak of upcoming Switch 2 game details as…
Want a few new video games? Well, there are some incredible deals on Switch and…
A newly disclosed security vulnerability in Microsoft Teams could allow attackers to spoof local devices,…
A critical security flaw has been discovered in SandboxJS, a widely used JavaScript sandboxing library…
Email filters are important, but they can’t remove phishing risk on their own. Today’s campaigns are built to…
This website uses cookies.