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:
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:
Every sub-component also accepts
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
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.isOpen
Whether the dialog is open. When provided, the component is controlled.onClose
Callback invoked when the dialog requests to close (outside click, Escape, or cancel).closeOnOutsideClick
Whether clicking outside the dialog closes it.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.
onError
Callback when an SDK error occurs.className
Additional CSS class applied to the dialog backdrop.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".