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, popovers 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 email addresses 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.
An app that sets no direction and has no dir="rtl" on its page lays out left to right, exactly as before.

Layout Direction and Language

Layout direction and language are two separate settings: Choosing Arabic translates the UI Kit but doesn’t change its layout. By default the UI Kit follows your page’s direction, which your app sets from the language. You can also set them apart, for example an English app laid out RTL, or an Arabic app kept LTR.

Turn On RTL

Follow the page’s direction (default)

With the default value, 'auto', the UI Kit follows your app: set dir on <html> and every component lays out to match. This is the recommended setup for an app that is itself right to left.
The UI Kit never writes <html dir>. If your app switches language at runtime, set the page’s direction from the language yourself:
CometChatLocalize.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.
CometChatUIKit.init() selects the browser’s language. To use a language your user picked, call CometChatLocalize.setCurrentLanguage() after init(), then set <html dir> before your app renders, so the first frame already has the right direction. Components work out some text (dates, previews, labels) when they are created, so after a language change, recreate the screen or reload the page.

Set it for the whole UI Kit

Call setLayoutDirection() on the UIKitSettingsBuilder to give every UI Kit component a fixed direction, whatever the page’s direction. Your own components and the rest of the page are not affected:

Change it at runtime

Use CometChatUIKit.setLayoutDirection() to change the direction while the app is running, for example from a settings screen:
The new direction applies to UI Kit components created after the change. Components already on screen keep their direction until they are created again, for example when the user reopens the screen. Call it after init(): init() applies the builder’s setting ('auto' if you didn’t set one), so a direction set before init() is replaced.

Set It Per Component

The feature components listed below take a layoutDirection input, 'ltr' or 'rtl'. It overrides the global setting for that component and the UI Kit components inside it, including the menus, popovers and dialogs it opens:
Leave it unset to inherit the direction from the UI Kit component around it, or from the global setting. Unlike the global setting, changing the input updates the component at once. The input is on: Every message bubble takes it too: Text, Card, Image, Video, Audio, File, Action, Delete, Call, Poll, Collaborative Document, Collaborative Whiteboard and Sticker. Every other component has no input of its own: it follows the component it sits in, and used on its own it follows the global setting. A [layoutDirection] binding on one of these fails to compile. They are:
  • Base elements: avatar, button, checkbox, radio button, dropdown, list item, date, popover, context menu, toast, action sheet, search bar, typing indicator, error boundary and fullscreen viewer.
  • Dialogs and pickers: confirm dialog, pin and save confirm dialog, flag message dialog, change scope, link dialog and link popover, emoji keyboard and media recorder.
  • Message parts: message preview and thread view.
  • AI: Smart Replies, Conversation Starter and Conversation Summary.
  • The search result lists (cometchat-search-messages-list and cometchat-search-conversations-list), which follow the Search component they sit in.

Which Setting Wins

When settings disagree, the first rule that gives a direction wins:
  1. Audio and video players and the voice recorder 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 as it was when that component was created.
  4. The global setting, when it is 'ltr' or 'rtl'.
  5. The page’s direction: the dir of <html>, or of an element the component sits inside.
The UI Kit writes the result as dir on the component’s host element. With nothing set and the global setting 'auto', it writes no dir at all.
When the global setting is 'ltr' or 'rtl', wrapping a component in an element with its own dir does not change the component’s direction:
The global setting is written on each component’s host element, so it wins over the wrapper. Use the component’s input instead: <cometchat-conversations layoutDirection="ltr">. A dir wrapper works only while the global setting is 'auto'.

Pages 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 components, headers and navigation stay as they are. To give one of your own sections the same direction, set dir on it:
To mirror the whole app, set <html dir="rtl"> and leave the UI Kit on 'auto'.

Common Scenarios

In the last case, components side by side, such as a header, message list and composer, each need the input, or wrap them in <div dir="rtl">: a wrapper works because the global setting is 'auto'.

What Changes in RTL

Layout

Everything that has a side moves to the other one: avatars, titles, subtitles, timestamps, unread badges, receipts, buttons, the composer’s actions, message bubbles, menus, popovers, dialogs, toasts, tooltips and loading skeletons. Sent messages sit on the left and received messages on the right. Menus, popovers and tooltips are placed by the direction and stay on screen near both edges. A placement of left or right on a popover or context menu is mirrored in RTL, so a menu set to open at the end side still does. The left and right arrow keys follow the layout: in a right-to-left list, the left arrow moves to the next item.

Icons

Icons you pass into the UI Kit, such as your own iconURL on a menu option, are drawn as you give them.

What doesn’t mirror

  • Audio and video players, including voice notes, the voice recorder and the fullscreen viewer: playback controls, waveforms and progress bars stay left to right in every language. The bubble around the player still follows the layout.
  • Code blocks, in chat messages and in AI assistant replies, always read left to right.
  • The link dialog’s URL field in the composer reads left to right.
  • Counters such as +3 on an image grid or a reactions row keep their sign in front.
  • The call screen during a call (cometchat-ongoing-call) is the Calls SDK’s own UI: its participants panel, layout and settings menus and toasts always stay left to right.

Message text

  • Each message reads in its own direction. The first letter decides it: a message that starts with an English letter reads left to right, one that starts with an Arabic letter reads right to left. Conversation subtitles, search results, saved messages and the composer’s reply and edit previews do the same.
  • Names and mentions keep their place. A sender’s name is isolated, so it can’t reorder the text around it (the : after a name stays after it), and a mention always reads @name.
  • Links, inline code and email addresses take their own direction: a URL or an email address reads left to right inside Arabic text.
  • The UI Kit’s own labels (empty and error states, dialog text, toasts) read in the UI language’s direction, so an English label in an RTL layout keeps its punctuation at the end. Their position still follows the layout.
  • Numbers and dates. When the UI Kit’s language is Arabic (ar), the dates, times and counts it formats use Arabic-Indic digits (٠١٢٣٤٥٦٧٨٩). A regional tag, such as ar-MA, uses that region’s own digits. Member counts, reply counts and “last seen” use Arabic’s plural forms (“عضوان”, “١١ عضوًا”). See Count Texts. Text you supply yourself is shown as given.

Message composer

  • The text follows the language you type: an English line starts at the left, an Arabic line at the right, in either layout direction.
  • The placeholder stays on the layout’s start side.

Custom Views in RTL

Templates you pass into the UI Kit (item, leading, title, subtitle, trailing and header views, custom bubbles) render inside the component’s host element and inherit its direction. A UI Kit component you place inside one of these templates inherits from the UI Kit component around it. Write your templates and CSS so they mirror with the rest of the UI Kit. Use CSS logical properties. The UI Kit’s own stylesheets use them, so they mirror on their own. Physical properties still work in a left-to-right layout exactly as before, but don’t mirror: Style by direction with :dir(rtl), not [dir="rtl"] .x or :host-context([dir="rtl"]). A component set to 'ltr' on an RTL page is still inside <html dir="rtl">, so an attribute selector matches it wrongly. :dir() matches the direction the element actually lays out in (Chrome 120, Safari 16.4 and Firefox 49 or later):
Read the direction from the element in code, not from <html> or the global setting. It is right even when you set the UI Kit’s direction with layoutDirection and it differs from the page’s:
Pass the direction to overlays you open yourself. The UI Kit’s own menus and dialogs carry the direction of the component that opens them. An overlay you attach to document.body, such as an Angular CDK overlay, leaves that component’s DOM, so copy the direction from the element it opens from. With the CDK, pass it as the overlay’s direction:
Or set dir on the overlay’s pane yourself: overlayRef.overlayElement.setAttribute('dir', direction).

Languages

The UI Kit ships Arabic (ar) translations; regional tags such as ar-SA and ar-EG use them too. Select it after init():
To lay out only the UI Kit right to left without changing your page, leave out the dir line and use setLayoutDirection('rtl') instead. To change any Arabic string, override it as you would for any other language: see Global Translation Overrides. For another RTL language, such as Hebrew, Persian or Urdu, add it as described in Adding a New Language, then set <html dir="rtl"> or setLayoutDirection('rtl'). CometChatLocalize.getDirection() already reports 'rtl' for he, fa and ur.

Next Steps

Localization

Set the UI Kit’s language and translations

Methods

UIKitSettingsBuilder and CometChatUIKit reference

Theming

Colors, fonts and dark mode

Troubleshooting

Common RTL questions