Skip to main content

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

Root CSS class: .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, omit Remark to collect only a reason:

Custom Header

Pass title/subtitle for text changes, or children for fully custom header content:
Sub-component props: 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. Return true 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 isOpen and onClose. 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 calls CometChat.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 as undefined to onSubmit. A character counter enforces maxLength (default 500).

Submission

The submit button is disabled until a reason is selected. On submit:
  1. onSubmit is awaited.
  2. Returning false (or throwing) keeps the dialog open and shows an inline error banner.
  3. Returning true closes 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 with Tab / 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

The message 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. Return true 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" with aria-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+Tab cycle through focusable elements.
  • Escape closes the dialog.
  • The error banner uses role="alert" with aria-live="assertive".