> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# RTL Support

> Show CometChat React UI Kit components right to left for Arabic and other RTL languages, for the whole kit or per component, with layoutDirection.

> [accordion] AI Integration Quick Reference
>
> | Field | Value |
> | - | - |
> | Package | `@cometchat/chat-uikit-react` 7.4.0 or later |
> | Import | `import { CometChatProvider, CometChatUIKit, UIKitSettingsBuilder, CometChatLocalize } from "@cometchat/chat-uikit-react";` |
> | Purpose | Show UI Kit components right to left (RTL) or left to right (LTR), for the whole kit or for one component. |
> | Global setting | `UIKitSettingsBuilder.setLayoutDirection(...)` at init, `<CometChatProvider layoutDirection>`, or `CometChatUIKit.setLayoutDirection(...)` at runtime |
> | Per component | `layoutDirection` prop on the UI Kit components (and on the `Root` of compound components) |
> | Values | Global: `'auto'` (default) · `'ltr'` · `'rtl'`. Component prop: `'ltr'` · `'rtl'` (leave it unset to inherit) |
> | Default behavior | `'auto'` follows the page's direction (`<html dir>`), so a page that is already RTL needs no extra code |
> | Page direction | `CometChatLocalize.getDirection(language)` returns `'ltr'` or `'rtl'` for a language, to set `<html dir>` from |
> | Your own views | CSS logical properties (`margin-inline-start`, `inset-inline-end`, `text-align: start`); the `cometchat-icon--mirror` class flips a directional icon in RTL |
> | Type | `CometChatLayoutDirection` (`'auto' \| 'ltr' \| 'rtl'`), exported for typing your own settings state |
> | Related | [Localization](https://www.cometchat.com/docs/ui-kit/react/localization.md) · [CometChatProvider](https://www.cometchat.com/docs/ui-kit/react/cometchat-provider.md) · [Methods](https://www.cometchat.com/docs/ui-kit/react/methods.md) · [Theming](https://www.cometchat.com/docs/ui-kit/react/theming.md) |

## Overview

Languages such as Arabic are read right to left. In an RTL layout, the UI Kit mirrors every component: avatars, names, buttons, message bubbles, menus and dialogs swap sides, and arrows point the other way.

Mirroring the layout doesn't mean flipping the content. The UI Kit keeps every piece of content readable:

* Each message reads in its own direction, so an English message in an Arabic chat still reads left to right.
* Names, mentions and numbers keep their order inside the text around them.
* Audio and video players and code blocks stay left to right, as they do in every RTL app.

***

## Layout Direction and Language

Layout direction and language are two separate settings:

| Setting | Decides | Set with |
| - | - | - |
| Layout direction | Which side things sit on | `<html dir>`, or the UI Kit's `layoutDirection` |
| Language | Which strings are shown | `locale` on `CometChatProvider` (see [Localization](https://www.cometchat.com/docs/ui-kit/react/localization.md)) |

The UI Kit never changes the page's `dir`. By default it follows the page, so an app that sets `<html dir="rtl">` for Arabic gets an RTL UI Kit. You can also set them apart, for example an English app with the UI Kit laid out RTL, or an Arabic app with the UI Kit kept LTR.

***

## Turn On RTL

### Follow the page's direction (default)

With the default value, `'auto'`, the UI Kit uses the direction the page is already in. Set `lang` and `dir` on `<html>` from the user's language, and pass the same language to `CometChatProvider`. `CometChatLocalize.getDirection()` tells you which `dir` a language needs:

```tsx theme={null}
import { useLayoutEffect } from "react";
import { CometChatLocalize, CometChatProvider } from "@cometchat/chat-uikit-react";

function App({ language }: { language: string }) {
  // Before the browser paints, so an RTL language never shows one LTR frame.
  useLayoutEffect(() => {
    document.documentElement.lang = language;
    document.documentElement.dir = CometChatLocalize.getDirection(language); // 'ar' → 'rtl'
  }, [language]);

  return (
    <CometChatProvider locale={language}>
      <MyChatApp />
    </CometChatProvider>
  );
}
```

`getDirection()` returns `'rtl'` for every language written in a right-to-left script, in any region: Arabic (`ar`, `ar-SA`), Hebrew, Persian, Urdu, Pashto, Sindhi, Sorani Kurdish, Uyghur, Yiddish and Dhivehi, and tags that name such a script (`pa-Arab`). It returns `'ltr'` for everything else. With no argument, it uses the language the UI Kit is actually showing: a language with no strings of its own, such as `he` before you add Hebrew, shows English and returns `'ltr'`. It only reports the direction; it changes nothing.

> [!NOTE]
>
> Menus, popovers, emoji pickers and dialogs are rendered in the UI Kit's root element (the `CometChatProvider`), outside the component that opens them, so a `dir` around one component doesn't reach them. Set `dir` on `<html>` or around the whole `CometChatProvider`, or use `layoutDirection`.

### Set it for the whole UI Kit

Set `layoutDirection` to give every UI Kit component a fixed direction, whatever the page's direction. Your own page is not affected. Set it on the `UIKitSettingsBuilder` at init:

```tsx theme={null}
import { CometChatUIKit, UIKitSettingsBuilder } from "@cometchat/chat-uikit-react";

const settings = new UIKitSettingsBuilder()
  .setAppId("APP_ID")
  .setRegion("REGION")
  .setAuthKey("AUTH_KEY")
  .setLayoutDirection("rtl")
  .build();

await CometChatUIKit.init(settings);
```

Or pass it to `CometChatProvider`. It is the same global setting; when you pass the prop, it takes precedence over the builder's value:

```tsx theme={null}
<CometChatProvider locale="ar" layoutDirection="rtl">
  <MyChatApp />
</CometChatProvider>
```

| Value | Result |
| - | - |
| `'auto'` | Follows the page's direction. This is the default, so apps that don't set it see no change. |
| `'ltr'` | Every UI Kit component is left to right. |
| `'rtl'` | Every UI Kit component is right to left. |

### Change it at runtime

To switch the direction while the app is running, for example from a settings menu, keep it in state and pass it to `CometChatProvider`. The UI Kit components inside re-render in the new direction:

```tsx theme={null}
import { useState } from "react";
import { CometChatProvider } from "@cometchat/chat-uikit-react";
import type { CometChatLayoutDirection } from "@cometchat/chat-uikit-react";

function App() {
  const [direction, setDirection] = useState<CometChatLayoutDirection>("auto");

  return (
    // 'auto' is passed as "not set", so it doesn't hide a direction set at init.
    <CometChatProvider layoutDirection={direction === "auto" ? undefined : direction}>
      <MyChatApp onDirectionChange={setDirection} />
    </CometChatProvider>
  );
}
```

Outside React, use `CometChatUIKit.setLayoutDirection()`. `CometChatUIKit.getLayoutDirection()` returns the current value:

```tsx theme={null}
import { CometChatUIKit } from "@cometchat/chat-uikit-react";

CometChatUIKit.setLayoutDirection("rtl");
```

> [!NOTE]
>
> * `CometChatUIKit.setLayoutDirection()` applies to UI Kit components mounted after the call. Components already on screen keep their direction until they mount again, for example when the user reopens the screen. The `CometChatProvider` prop applies immediately.
> * `CometChatUIKit.init()` always applies the builder's value, which is `'auto'` when you don't set one. Call `setLayoutDirection()` after `init()`, not before.
> * While you pass `layoutDirection` to the provider, it wins over the builder and `setLayoutDirection()`, even when you pass `"auto"`. Leave the prop unset to use their value.

***

## Set It Per Component

The UI Kit components take a `layoutDirection` prop. It overrides the global setting for that component and everything inside it, including the menus, popovers and dialogs it opens:

```tsx theme={null}
// The whole UI Kit is RTL, but this list stays LTR.
<CometChatConversations layoutDirection="ltr" />
```

In the compound API, pass it to the `Root`:

```tsx theme={null}
<CometChatConversations.Root layoutDirection="ltr">
  {/* ... */}
</CometChatConversations.Root>
```

Leave it unset to inherit the direction from the UI Kit component around it, or from the global setting.

These components take `layoutDirection`:

| Chat | Messages | Bubbles | Calls and more |
| - | - | - | - |
| [Conversations](https://www.cometchat.com/docs/ui-kit/react/components/conversations.md) | [Message Header](https://www.cometchat.com/docs/ui-kit/react/components/message-header.md) | [Message Bubble](https://www.cometchat.com/docs/ui-kit/react/components/message-bubble.md) | [Call Buttons](https://www.cometchat.com/docs/ui-kit/react/components/call-buttons.md) |
| [Users](https://www.cometchat.com/docs/ui-kit/react/components/users.md) | [Message List](https://www.cometchat.com/docs/ui-kit/react/components/message-list.md) | [Text Bubble](https://www.cometchat.com/docs/ui-kit/react/components/text-bubble.md) | [Incoming Call](https://www.cometchat.com/docs/ui-kit/react/components/incoming-call.md) |
| [Groups](https://www.cometchat.com/docs/ui-kit/react/components/groups.md) | [Message Composer](https://www.cometchat.com/docs/ui-kit/react/components/message-composer.md) | [Image Bubble](https://www.cometchat.com/docs/ui-kit/react/components/image-bubble.md) | [Outgoing Call](https://www.cometchat.com/docs/ui-kit/react/components/outgoing-call.md) |
| [Group Members](https://www.cometchat.com/docs/ui-kit/react/components/group-members.md) | [Thread Header](https://www.cometchat.com/docs/ui-kit/react/components/thread-header.md) | [Video Bubble](https://www.cometchat.com/docs/ui-kit/react/components/video-bubble.md) | [Call Logs](https://www.cometchat.com/docs/ui-kit/react/components/call-logs.md) |
| [Search](https://www.cometchat.com/docs/ui-kit/react/components/search.md) | [Pinned Messages](https://www.cometchat.com/docs/ui-kit/react/components/pinned-messages.md) | [Audio Bubble](https://www.cometchat.com/docs/ui-kit/react/components/audio-bubble.md) | `CometChatOngoingCall` |
| [Notification Feed](https://www.cometchat.com/docs/ui-kit/react/components/notification-feed.md) | [Saved Messages](https://www.cometchat.com/docs/ui-kit/react/components/saved-messages.md) | [Voice Note Bubble](https://www.cometchat.com/docs/ui-kit/react/components/voice-note-bubble.md) | [AI Assistant Chat](https://www.cometchat.com/docs/ui-kit/react/components/ai-assistant-chat.md) |
| | [Message Information](https://www.cometchat.com/docs/ui-kit/react/components/message-information.md) | [File Bubble](https://www.cometchat.com/docs/ui-kit/react/components/file-bubble.md) | `CometChatAIAssistantChatHistory` |
| | [Reactions](https://www.cometchat.com/docs/ui-kit/react/components/reactions.md) | [Poll Bubble](https://www.cometchat.com/docs/ui-kit/react/components/poll-bubble.md) | `CometChatCreatePoll` |
| | [Reaction List](https://www.cometchat.com/docs/ui-kit/react/components/reaction-list.md) | [Sticker Bubble](https://www.cometchat.com/docs/ui-kit/react/components/sticker-bubble.md) | |
| | [Flag Message Dialog](https://www.cometchat.com/docs/ui-kit/react/components/flag-message-dialog.md) | [Collaborative Document Bubble](https://www.cometchat.com/docs/ui-kit/react/components/collaborative-document-bubble.md) | |
| | | [Collaborative Whiteboard Bubble](https://www.cometchat.com/docs/ui-kit/react/components/collaborative-whiteboard-bubble.md) | |
| | | [Call Bubble](https://www.cometchat.com/docs/ui-kit/react/components/call-bubble.md) | |
| | | [Call Action Bubble](https://www.cometchat.com/docs/ui-kit/react/components/call-action-bubble.md) | |
| | | [Group Action Bubble](https://www.cometchat.com/docs/ui-kit/react/components/group-action-bubble.md) | |

The single-item bubbles (`CometChatImageBubble`, `CometChatVideoBubble`, `CometChatAudioBubble`, `CometChatFileBubble`) and the AI bubbles (`CometChatAIAssistantBubble`, `CometChatStreamMessageBubble`, `CometChatToolCallArgumentBubble`, `CometChatToolCallResultBubble`) take it too. The Card and Delete bubbles have no prop of their own and follow the component around them.

> [!NOTE]
>
> On `CometChatOngoingCall`, `layoutDirection` sets the direction of the UI Kit's call overlay. The call screen inside it is the Calls SDK's own UI and always stays left to right.

***

## Which Setting Wins

When settings disagree, the first rule that gives a direction wins:

1. Audio and video players are always left to right.
2. The component's own `layoutDirection`.
3. The nearest UI Kit component around it: its own `layoutDirection`, or the global setting it resolved.
4. The global setting, when it is `'ltr'` or `'rtl'`: the `CometChatProvider` prop when you pass it, otherwise the value from the builder or `CometChatUIKit.setLayoutDirection()` as it was when the component mounted.
5. The page's own direction (`dir` on `<html>` or on an element around the component). With nothing set, the UI Kit writes no `dir` of its own.

With a global `'ltr'` or `'rtl'`, or a component prop, the UI Kit writes `dir` on its own elements, so a `dir` on an element around it has no effect. To force one component's direction, use its `layoutDirection` prop.

***

## App UI Outside the UI Kit

The UI Kit never changes your page's direction. With a global `'ltr'` or `'rtl'`, the UI Kit's components follow it but your own UI stays as it is. To give your own UI the same direction, set `dir` on its root element, or set `<html dir>` and leave the UI Kit on `'auto'`:

```tsx theme={null}
function SettingsPanel() {
  return <section dir="rtl">{/* your UI */}</section>;
}
```

***

## What Changes in RTL

### Layout

The UI Kit's stylesheets use CSS logical properties, so everything that has a side moves to the other one: avatars, titles, subtitles, timestamps, unread badges, receipts, buttons, the composer's actions, message bubbles, reactions, menus, dialogs and loading skeletons. Sent messages sit on the left and received messages on the right.

* Menus, popovers, tooltips, the emoji and reaction pickers and the mention list open on the side that suits the direction, and stay on screen near both edges. A submenu stays inside the same box as its menu.
* In horizontal lists you move through with the arrow keys (the emoji and sticker tabs, the reactions bar, the reaction list's tabs, the full-screen media viewer), the Left arrow moves forward in RTL.
* The kit's own labels read in the direction of the language they are shown in, whatever the layout direction. In an English UI laid out RTL, "This action cannot be undone." keeps its full stop at the end and "2 Members" keeps its order.

### Icons

| Icon | In RTL |
| - | - |
| Arrows that point along the reading direction: back, forward, sideways chevrons, send, reply, reply in thread, send privately, and the call-direction arrows (incoming, outgoing and missed, voice and video) | Flip |
| Video camera, copy, chat, sticker, and the composer's list and quote icons | Flip |
| Everything else: a bare phone handset, microphone, attach, emoji, close, search, receipt ticks, pin, media controls, file types, logos, and the AI chat's send arrow, which points up | Stay as drawn |

Icons you pass into the UI Kit, for example an `iconURL` in a menu option, are drawn as you give them. To flip one of your own directional icons, see [Custom Views in RTL](#custom-views-in-rtl).

### What doesn't mirror

* **Audio and video players**, including voice notes, the voice recorder, the attachment tray's audio tile and the full-screen viewer: playback controls, waveforms and progress bars stay left to right in every language.
* **Code blocks**, in messages and in AI assistant replies, and the AI tool-call argument and result JSON always read left to right. Inline code takes the direction of its own text.
* **The URL field** of the composer's link dialog is always left to right.
* **Counts** such as "+2" on image grids, file lists and reactions keep the plus in front.
* **The call screen** during a call (`CometChatOngoingCall`) is the Calls SDK's own UI: its participants panel, layout and settings menus and toasts always stay left to right.

### Message text

* **Each paragraph reads in its own direction.** Its first letter decides it, skipping mentions, links and code: a paragraph that starts with an English letter reads left to right, one that starts with an Arabic letter reads right to left. The bubble stays on its side either way.
* **Names and mentions keep their place.** A user's name can't scramble the sentence around it, and a mention always reads `@name`.
* **Links** take their own direction: a URL reads left to right, an Arabic link label right to left. **Email addresses** read left to right.
* **Content the UI Kit shows**, such as smart replies, AI replies and suggestions, link previews, notification cards and conversation summaries, takes its own direction, as message bubbles do.

### Message composer and text fields

* In the composer, each line takes its direction from its text, so the caret stays after the last letter when you type English in an RTL layout. A bulleted or numbered list takes the direction of its first letter. The direction is not sent with the message.
* Text fields, such as the search bars, poll question and options, report remark and link dialog, take the direction of the text typed in them. An empty field and its placeholder follow the layout.

### Numbers and dates

When the UI Kit's language is Arabic (`ar`), the dates and times it formats use Arabic digits (٠٦:٢٨ م) and the Arabic comma. A regional Arabic language keeps its region's digits. The message header's "last seen" text, including "just now" and AM/PM, is in the UI language.

Counts use the language's plural forms: group member counts, the "minutes ago" and "hours ago" of last seen, and thread reply counts. Arabic has six forms, so two members reads "عضوان" and two minutes ago "منذ دقيقتين". To change these texts, see [Count Texts](https://www.cometchat.com/docs/ui-kit/react/localization.md#count-texts).

***

## Custom Views in RTL

Views you pass into the UI Kit (view props such as `subtitleView`, custom bubbles, plugin views) are placed inside the component's direction. Style them with CSS logical properties so they mirror with the rest of the UI Kit:

| Instead of | Use |
| - | - |
| `margin-left`, `margin-right` | `margin-inline-start`, `margin-inline-end` |
| `padding-left`, `padding-right` | `padding-inline-start`, `padding-inline-end` |
| `left`, `right` (absolute position) | `inset-inline-start`, `inset-inline-end` |
| `text-align: left` | `text-align: start` |
| `border-top-left-radius` | `border-start-start-radius` |
| `float: left` | `float: inline-start` |

Physical properties still work in LTR exactly as before; they just don't mirror in RTL. The same applies to CSS overrides of the UI Kit's own classes.

When a view needs to know the direction itself, for example to flip an arrow, use the `:dir()` CSS pseudo-class, which reads the direction the UI Kit gives the element, or add the UI Kit's `cometchat-icon--mirror` class, which flips an icon in RTL:

```tsx theme={null}
import { CometChatConversations } from "@cometchat/chat-uikit-react";
import type { CometChat } from "@cometchat/chat-sdk-javascript";

<CometChatConversations
  subtitleView={(conversation: CometChat.Conversation) => (
    <div className="my-subtitle">
      <img className="cometchat-icon--mirror" src="/icons/arrow-forward.svg" alt="" />
      <span>{conversation.getLastMessage()?.getSender()?.getName() ?? ""}</span>
    </div>
  )}
/>
```

```css theme={null}
.my-subtitle {
  display: flex;
  gap: 4px;
  padding-inline-start: 8px;
  text-align: start;
}
```

To flip an icon yourself instead of using `cometchat-icon--mirror`, give it your own class and flip it with `:dir(rtl)`:

```tsx theme={null}
<img className="my-arrow" src="/icons/arrow-forward.svg" alt="" />
```

```css theme={null}
.my-subtitle:dir(rtl) .my-arrow {
  transform: scaleX(-1);
}
```

In JavaScript, read the element's computed direction rather than `document.dir`, because the UI Kit's direction can differ from the page's:

```tsx theme={null}
const isRtl = getComputedStyle(element).direction === "rtl";
```

***

## Languages

The UI Kit ships an Arabic translation (`ar`). A regional Arabic code with no strings of its own, such as `ar-SA`, uses `ar` before falling back to English. For another RTL language, such as Hebrew, Persian or Urdu, add its strings as described in [Localization](https://www.cometchat.com/docs/ui-kit/react/localization.md#adding-custom-translations), pass its code as `locale`, and set `<html dir>` with `CometChatLocalize.getDirection()` or set `layoutDirection` to `'rtl'`.

***

## Next Steps

> [card] [Localization](https://www.cometchat.com/docs/ui-kit/react/localization.md)
>
> Set the UI Kit's language and translations

> [card] [CometChatProvider](https://www.cometchat.com/docs/ui-kit/react/cometchat-provider.md)
>
> The provider's `locale` and `layoutDirection` props

> [card] [Methods](https://www.cometchat.com/docs/ui-kit/react/methods.md)
>
> `UIKitSettingsBuilder` and `CometChatUIKit` reference

> [card] [Troubleshooting](https://www.cometchat.com/docs/ui-kit/react/troubleshooting.md#rtl-layout)
>
> Common RTL questions


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.