An Angular component for displaying poll messages with voting functionality in a chat interface
The CometChatPollBubble component is a standalone Angular component that renders poll messages with voting functionality within chat conversations. It extracts poll data from CometChat CustomMessage metadata and displays the poll question, voting options with radio buttons, vote counts, progress bars, and voter avatars.
The Poll Bubble component provides a comprehensive display for poll messages with support for both sender (outgoing) and receiver (incoming) styling variants:
Poll Question Display: Shows the poll question prominently at the top
Voting Options: Displays all poll options with radio buttons for selection
Vote Counts: Shows the number of votes for each option
Progress Bars: Visual representation of vote distribution percentages
Voter Avatars: Displays up to 3 voter avatars per option in a stacked layout
Vote Submission: Allows users to vote by clicking options via CometChat polls extension API
Sender/Receiver Variants: Different styling for outgoing vs incoming poll messages
Full Accessibility Support: ARIA labels, keyboard navigation, and screen reader support
CSS Variable-Based Theming: Easy customization via CSS variables
The CometChat CustomMessage object containing poll data in its metadata. Poll data is extracted from the path @injected.extensions.polls
alignment
MessageBubbleAlignment
MessageBubbleAlignment.left
Determines sender (right) or receiver (left) styling. When right, applies primary color background with white text. When left, applies neutral background with neutral text
loggedInUser
CometChat.User
undefined
The currently logged-in user. Used to determine which poll options the user has selected (shows checked radio button)
disableInteraction
boolean
false
When true, disables voting and other interactive elements within the poll bubble
interface PollVoteEvent { /** The poll ID */ pollId: string | number; /** The selected option ID */ optionId: string; /** The selected option text */ optionText: string; /** The message containing the poll */ message: CometChat.CustomMessage;}
interface PollVoteErrorEvent { /** The poll ID */ pollId: string | number; /** The attempted option ID */ optionId: string; /** The error that occurred */ error: Error; /** The message containing the poll */ message: CometChat.CustomMessage;}
Screen readers announce each poll option with its text and vote count (e.g., “Option A - 5 votes”). The radiogroup role ensures screen readers understand this is a selection interface. Progress bars are announced with their percentage values.
Use the poll bubble to display poll messages in your chat interface, allowing users to vote and see real-time results.
The component requires a valid CometChat.CustomMessage with poll data in its metadata at the path @injected.extensions.polls. Ensure the polls extension is enabled in your CometChat dashboard.
Pass the loggedInUser input to show which options the current user has selected. Without this, all radio buttons will appear unselected.
Listen to the voteSubmit event to update your local message state after a successful vote. The CometChat SDK will also send real-time updates for poll votes.
All text in the component is localized. The component uses localization keys like poll_bubble_options_label, poll_bubble_votes, and poll_bubble_no_options.
Users can change their vote by clicking a different option. The component does not prevent re-voting - this is handled by the CometChat polls extension.