Skip to main content

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: 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:
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.
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:
Or pass it to CometChatProvider. It is the same global setting; when you pass the prop, it takes precedence over the builder’s value:

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:
Outside React, use CometChatUIKit.setLayoutDirection(). CometChatUIKit.getLayoutDirection() returns the current value:
  • 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:
In the compound API, pass it to the Root:
Leave it unset to inherit the direction from the UI Kit component around it, or from the global setting. These components take layoutDirection: 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.
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':

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

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.

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.

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: 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:
To flip an icon yourself instead of using cometchat-icon--mirror, give it your own class and flip it with :dir(rtl):
In JavaScript, read the element’s computed direction rather than document.dir, because the UI Kit’s direction can differ from the page’s:

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, pass its code as locale, and set <html dir> with CometChatLocalize.getDirection() or set layoutDirection to 'rtl'.

Next Steps

Localization

Set the UI Kit’s language and translations

CometChatProvider

The provider’s locale and layoutDirection props

Methods

UIKitSettingsBuilder and CometChatUIKit reference

Troubleshooting

Common RTL questions