AI Integration Quick Reference
AI Integration Quick Reference
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.
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.
<html dir>. If your app switches language at runtime, set the page’s direction from the language yourself:
- TypeScript
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
CallsetLayoutDirection() 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:
- TypeScript
Change it at runtime
UseCometChatUIKit.setLayoutDirection() to change the direction while the app is running, for example from a settings screen:
- TypeScript
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 alayoutDirection 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:
- HTML
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-listandcometchat-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:- Audio and video players and the voice recorder are always left to right.
- The component’s own
layoutDirection. - The nearest UI Kit component around it: its own
layoutDirection, or the global setting as it was when that component was created. - The global setting, when it is
'ltr'or'rtl'. - The page’s direction: the
dirof<html>, or of an element the component sits inside.
dir on the component’s host element. With nothing set and the global setting 'auto', it writes no dir at all.
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:
- HTML
<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. Aplacement 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
+3on 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 asar-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):
- CSS
<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:
- TypeScript
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:
- TypeScript
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():
- TypeScript
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