Skip to main content
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.

Overview

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
  • OnPush Change Detection: Optimized performance
Live Preview — Default poll bubble preview. Open in Storybook ↗

Basic Usage

Simple Poll Bubble (Receiver Variant)

Sender Variant (Outgoing Poll)

With Logged-In User and Vote Events

Incoming vs Outgoing Polls

Properties

Events

PollVoteEvent Interface

PollVoteErrorEvent Interface

Poll Data Structure

The component extracts poll data from the message metadata at the path @injected.extensions.polls. The expected structure is:

Customization

Styling with CSS Variables

The Poll Bubble component uses CSS variables exclusively for easy customization:

Available CSS Variables

Custom Color Schemes

Custom Sizing

Accessibility

The Poll Bubble component is fully accessible and follows WCAG 2.1 Level AA guidelines.

WCAG 2.1 Compliance

The component meets the following WCAG 2.1 success criteria:
  • 1.1.1 Non-text Content (Level A): Progress bars have aria-label with percentage information
  • 1.3.1 Info and Relationships (Level A): Proper semantic structure with role=“radiogroup” and role=“radio”
  • 1.4.3 Contrast (Minimum) (Level AA): Sufficient color contrast for text readability
  • 2.1.1 Keyboard (Level A): All options are keyboard accessible via Tab, Enter, and Space
  • 2.4.7 Focus Visible (Level AA): Visible focus indicators on interactive elements
  • 4.1.2 Name, Role, Value (Level A): All elements have accessible names and roles

ARIA Attributes

The component automatically applies appropriate ARIA attributes:

Keyboard Navigation

Screen Reader Behavior

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.

Color Contrast

Both sender and receiver variants maintain sufficient color contrast:
  • Sender variant: White text on primary color background (typically purple #6852D6)
  • Receiver variant: Primary text color on neutral background

Best Practices

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.
  • CometChatTextBubble: Displays text messages
  • CometChatImageBubble: Displays image messages
  • CometChatFileBubble: Displays file messages
  • CometChatDeleteBubble: Displays deleted message placeholders
  • CometChatActionBubble: Displays action/system messages
  • CometChatMessageList: Displays lists of messages including poll messages
  • CometChatRadioButton: Used internally for option selection
  • CometChatAvatar: Used internally for voter avatars

Technical Details

  • Standalone Component: Can be imported and used independently
  • Change Detection: Uses OnPush change detection strategy for optimal performance
  • Dependencies: Uses CometChatLocalize for text localization, CometChatRadioButton for options, CometChatAvatar for voter display
  • Bundle Size: Minimal footprint (~5KB)
  • BEM CSS: Follows Block Element Modifier naming convention
  • Accessibility: WCAG 2.1 Level AA compliant
  • Width: Min 240px, Max 300px for consistent bubble sizing
  • Voter Avatars: Maximum 3 displayed per option with stacked layout
  • Vote API: Uses CometChat.callExtension('polls', 'POST', 'v2/vote', {...}) for vote submission