Reaction Bar
Emoji reactions with counts under a message or comment, toggled by the current user, with a picker to add more.
c2-reaction-bar is the row of emoji reactions under a message, comment or post, as in Slack, GitHub and Discord. Each reaction is a pill with its count, pressed when the current user reacted with it; pressing it adds or removes their reaction. The button at the end opens quick reactions and, in its picker slot, a full c2-emoji-picker.
Import
import '@c2n/components/reaction-bar'
import '@c2n/components/emoji-picker' // for the picker slotUsage
Reactions
reactions is an array of { emoji, count, reacted }, as a property or as JSON in the attribute; emoji may be any short text, for custom reactions. Counts are shortened in the page’s language (1.3K). quick sets the reactions offered first in the popup, as emoji separated by spaces.
Changing a reaction
Pressing a pill, a quick reaction or an emoji in the picker fires reaction-change with the reaction as it is about to become (emoji, reacted, count), then updates reactions: a count that reaches 0 removes the pill and a new emoji is added at the end. Picking a reaction the user already gave keeps it. The event is cancelable: cancel it to keep the bar controlled, for example while the server confirms, and set reactions yourself.
bar.addEventListener('reaction-change', async (event) => {
event.preventDefault()
bar.reactions = await api.react(messageId, event.detail.emoji, event.detail.reacted)
})Accessibility
The bar is a group named “Reactions”. A screen reader hears each pill as its emoji and count, a toggle button pressed when you reacted. The add button opens a dialog of quick reactions, focused on the first; Escape or a pick closes it and returns focus to the button. readonly shows the pills as images whose name also says whether you reacted, with no add button.