AI Integration Quick Reference
AI Integration Quick Reference
Where It Fits
CometChatFlagMessageDialog is a modal dialog that lets a user report an inappropriate message. When it opens, it fetches the available report reasons from the SDK (CometChat.getFlagReasons), renders them as a single-select list, captures an optional free-text remark, and—on submit—invokes your onSubmit handler with the message ID, the selected reason ID, and the remark.
Live Preview — interact with the flag message dialog.Open in Storybook ↗
Use it when a user chooses “Report” on a message. The parent owns the open state and decides what happens with the report inside
onSubmit (e.g., calling a moderation backend).
Minimal Render
.cometchat-flag-message-dialog
Sub-Components
CometChatFlagMessageDialog is a compound component with these sub-components:
| Sub-Component | Purpose |
|---|---|
Root | Overlay and context provider. Manages open/close state, focus trap, outside-click/Escape, reason fetching, and submission. Renders the default layout when no children are passed. |
Header | Title and subtitle. Defaults to a localized “Report a Message” heading. |
Reasons | Single-select list of report reasons fetched from the SDK. |
Remark | Optional free-text input with a character counter (default max 500). |
Actions | Cancel and submit (Report) buttons. |
Custom Layout
Compose sub-components to customize the layout — for example, omitRemark to collect only a reason:
Custom Header
Passtitle/subtitle for text changes, or children for fully custom header content:
| Sub-component | Prop | Type | Default |
|---|---|---|---|
Header | title | string | "Report a Message" (localized) |
Header | subtitle | string | Localized description |
Remark | label | string | "Reason" (localized) |
Remark | placeholder | string | Localized placeholder |
Remark | maxLength | number | 500 |
Actions | cancelText | string | "Cancel" (localized) |
Actions | submitText | string | "Report" (localized) |
children (where applicable) and a className.
Actions and Events
Callback Props
onSubmit
Called when the user clicks Report with a reason selected. Receives the message ID, the selected reason ID, and the optional remark. Returntrue to close the dialog, or false to keep it open and show an inline error.
onClose
Called when the dialog requests to close — via the cancel button, the Escape key, or an outside click. In controlled mode you own the open state, so update it here.onError
Called when an SDK error occurs (e.g., while fetching reasons or during submission).Behavior Details
Controlled vs Uncontrolled
- Controlled — pass
isOpenandonClose. You own the open state (recommended for most apps). - Uncontrolled — omit
isOpen. The dialog manages its own internal open state and closes itself on cancel, Escape, outside click, or a successful submit.
Reason Fetching
On open, the dialog callsCometChat.getFlagReasons() and renders the result as a single-select list. While loading, a loading state is shown. If the call fails, onError is invoked.
Remark
The remark is optional. It is trimmed before submission, and an empty remark is passed asundefined to onSubmit. A character counter enforces maxLength (default 500).
Submission
The submit button is disabled until a reason is selected. On submit:onSubmitis awaited.- Returning
false(or throwing) keeps the dialog open and shows an inline error banner. - Returning
truecloses the dialog.
Focus & Keyboard
The Root traps focus within the dialog while open, moves focus to the first focusable element on open, restores focus to the previously focused element on close, cycles focus withTab / Shift+Tab, and closes on Escape.
CSS Architecture
The component uses CSS custom properties provided by the UI Kit.Key Selectors
| Target | Selector |
|---|---|
| Backdrop | .cometchat-flag-message-dialog__backdrop |
| Dialog container | .cometchat-flag-message-dialog |
| Error banner | .cometchat-flag-message-dialog__error |
| Header | .cometchat-flag-message-dialog__header |
| Header title | .cometchat-flag-message-dialog__header-title |
| Header subtitle | .cometchat-flag-message-dialog__header-subtitle |
| Reasons list | .cometchat-flag-message-dialog__reasons |
| Reason item | .cometchat-flag-message-dialog__reason |
| Reason item (selected) | .cometchat-flag-message-dialog__reason--selected |
| Reasons loading | .cometchat-flag-message-dialog__reasons-loading |
| Remark wrapper | .cometchat-flag-message-dialog__remark |
| Remark label | .cometchat-flag-message-dialog__remark-label |
| Remark input | .cometchat-flag-message-dialog__remark-input |
| Remark counter | .cometchat-flag-message-dialog__remark-counter |
| Remark counter (at limit) | .cometchat-flag-message-dialog__remark-counter--limit |
| Actions container | .cometchat-flag-message-dialog__actions |
| Cancel button | .cometchat-flag-message-dialog__actions-cancel |
| Submit button | .cometchat-flag-message-dialog__actions-submit |
Example: Custom styling
App.css
Props
Themessage prop is required. All other props are optional. The props below belong to Root (and to the flat CometChatFlagMessageDialog, which forwards them).
message
The message being flagged. Required.| Type | CometChat.BaseMessage |
| Default | — |
isOpen
Whether the dialog is open. When provided, the component is controlled.| Type | boolean |
| Default | undefined (uncontrolled) |
onClose
Callback invoked when the dialog requests to close (outside click, Escape, or cancel).| Type | () => void |
| Default | undefined |
closeOnOutsideClick
Whether clicking outside the dialog closes it.| Type | boolean |
| Default | true |
onSubmit
Custom submit handler. Receives the message ID, the selected reason ID, and the optional remark. Returntrue on success (the dialog closes) or false to keep it open and show an error.
| Type | (messageId: string, reasonId: string, remark?: string) => Promise<boolean> |
| Default | undefined |
onError
Callback when an SDK error occurs.| Type | ((error: CometChat.CometChatException) => void) | null |
| Default | undefined |
className
Additional CSS class applied to the dialog backdrop.| Type | string |
| Default | undefined |
Accessibility
- Root has
role="dialog"witharia-modal="true". - The dialog is labelled by its title (
aria-labelledby) and described by its subtitle (aria-describedby). - Focus moves into the dialog on open and is restored to the previously focused element on close.
- Focus is trapped within the dialog;
Tab/Shift+Tabcycle through focusable elements. Escapecloses the dialog.- The error banner uses
role="alert"witharia-live="assertive".