Skip to main content
Brand and assets
Build
Monitor and contribute
/
Front-end platform
  • Overview
  • Technical architecture
  • Core framework
  • Application
  • global-shell
  • modular-arch
  • Product shells
  • Modules & apps
  • Module directory
  • Apps
  • Bundles
  • Bundle explorer
  • Guides
  • Install Murray
  • Universal components
  • Build a universal component
  • Responsive styles
  • RTL support
  • Translations & i18n
  • When to use Form
  • Positioning elements
  • Add a new icon
  • Utilities
  • Overview
  • Layouts
  • RTL support

RTL (Right-to-Left) support

Learn how to build and maintain components that work in both LTR (left-to-right) and RTL (right-to-left) layouts.

What is RTL?​

RTL (right-to-left) refers to writing systems where text flows from right to left — Arabic, Hebrew, and Persian being the most common. When an application supports an RTL language, the entire UI layout mirrors horizontally: navigation moves to the right, text aligns right, and directional elements like arrows flip.

This is not just about text direction. The whole spatial model reverses: "start" becomes the right side, "end" becomes the left side.

Further reading:

  • MDN — dir global attribute
  • W3C — Structural markup and right-to-left text in HTML
  • Material Design — Bidirectionality

How Murray handles RTL​

Global direction​

MurrayBaseProvider automatically configures the text direction based on the current language. No additional configuration is needed.

import { MurrayProvider } from "murray";

function App() {
return <MurrayProvider>{/* Direction is automatically configured */}</MurrayProvider>;
}

Behind the scenes:

PlatformWhat happens
WebSets the dir and lang attributes on <html>
MobileCalls I18nManager.forceRTL() based on the current language. The withDisabledDeviceRTL Expo config plugin neutralizes device-locale-based RTL detection so that I18nManager.forceRTL() is the sole controller.
warning

On mobile, switching between LTR and RTL languages requires an app restart. This is a React Native limitation.

alan-i18n API​

When you need direction-aware logic (shadows, icons, conditional rendering), use the helpers from alan-i18n:

import { i18n, DIRECTION } from "alan-i18n";

// Get current direction: 'ltr' | 'rtl'
const direction = i18n.currentDirection();

// Boolean shorthand
const isRTL = i18n.isRTL();

// Example: flip shadow offset
const shadowStyle = {
shadowOffset: {
width: isRTL ? -2 : 2,
height: 2,
},
};

Local direction override​

Sometimes you need to display content in a different direction than the global setting — a brand name, a quote in another language, or a phone number. Use the dir and lang props on Murray typography components.

PropTypePurposeAffects
dirDirection | "auto"Visual rendering — how text is displayedText direction, alignment, layout
langLanguageAccessibility — how text is pronouncedScreen reader voice/pronunciation

dir values:

ValueBehavior
omittedInferred from lang if provided, otherwise inherit from parent
DIRECTION.ltrForce left-to-right
DIRECTION.rtlForce right-to-left
"auto"Auto-detect from first strong directional character (Unicode BiDi Algorithm)
tip
  • Use "auto" when text usually contains letters (brands, quotes, user content)
  • Use explicit DIRECTION.ltr / DIRECTION.rtl when content is primarily numbers, symbols, or punctuation (they are directionally neutral and "auto" would fall back to parent direction)

Examples:

import { Text, Paragraph } from "murray";
import { DIRECTION } from "alan-i18n";

// English quote in Arabic page — lang="en" infers LTR
<Paragraph>
قال المستخدم:
<Text lang="en">"I love using this application!"</Text>
</Paragraph>

// Brand name — stays LTR, pronounced in English
<Text lang="en">Alan</Text>

// Phone number — neutral chars need explicit LTR
<Text dir={DIRECTION.ltr}>+966 50 123 4567</Text>

// Arabic transliteration in Latin script — auto-detects LTR from Latin chars
<Text dir="auto" lang="ar">Marhaba!</Text>

All Murray typographic components are supported.


CSS logical properties​

Physical vs logical​

Physical CSS properties (margin-left, padding-right, left) are tied to the physical screen edges. They don't adapt when the text direction changes. Logical properties (margin-inline-start, padding-inline-end, inset-inline-start) are relative to the text direction and automatically flip in RTL.

Physical properties

topbottomleftrightElement

Fixed to screen edges.
Same in LTR and RTL.

Logical properties

block-startblock-endinline-startinline-endElementblock axis ↕inline axis ↔

Relative to text flow.
inline-start = left in LTR, right in RTL.

// ❌ Physical — does NOT adapt to RTL
<Box sx={{ marginLeft: 16, paddingRight: 8 }} />

// ✅ Logical — automatically flips in RTL
<Box sx={{ marginInlineStart: 16, paddingInlineEnd: 8 }} />

CSS/Tamagui vs React Native naming​

CSS and React Native use different naming conventions for logical properties. This is because CSS follows the CSS Logical Properties specification, while React Native's Yoga layout engine uses its own shorter naming.

Murray components use the CSS naming (they're built on Tamagui, which maps to CSS on web and translates for native). The React Native naming applies when using StyleSheet.create() or raw RN style objects.

PhysicalCSS / Tamagui (Murray)React Native
marginLeftmarginInlineStartmarginStart
marginRightmarginInlineEndmarginEnd
paddingLeftpaddingInlineStartpaddingStart
paddingRightpaddingInlineEndpaddingEnd
leftinsetInlineStartstart
rightinsetInlineEndend
borderLeftborderInlineStart—
borderRightborderInlineEnd—
borderLeftWidthborderInlineStartWidthborderStartWidth
borderRightWidthborderInlineEndWidthborderEndWidth
borderLeftStyleborderInlineStartStyle—
borderRightStyleborderInlineEndStyle—
borderLeftColorborderInlineStartColorborderStartColor
borderRightColorborderInlineEndColorborderEndColor
borderTopLeftRadiusborderStartStartRadiusborderTopStartRadius
borderTopRightRadiusborderStartEndRadiusborderTopEndRadius
borderBottomLeftRadiusborderEndStartRadiusborderBottomStartRadius
borderBottomRightRadiusborderEndEndRadiusborderBottomEndRadius
scrollMarginLeftscrollMarginInlineStart—
scrollMarginRightscrollMarginInlineEnd—
scrollPaddingLeftscrollPaddingInlineStart—
scrollPaddingRightscrollPaddingInlineEnd—

Migration guide​

1. Run the ESLint autofix​

The alan/no-physical-properties ESLint rule detects physical properties in style objects and auto-fixes them when the context is unambiguous.

yarn eslint <path-to-your-files> --fix

What gets auto-fixed (CSS context): sx prop, css prop, css() calls, styled() calls — replaced with CSS logical properties (e.g. marginLeft → marginInlineStart).

What does NOT get auto-fixed (ambiguous context): style prop, StyleSheet.create(), plain object literals — the rule reports an error but you must manually choose between CSS or React Native logical properties depending on the platform context.

info

Property shorthands are preserved: <Box sx={{ marginLeft }} /> becomes <Box sx={{ marginInlineStart: marginLeft }} /> (the variable is not renamed).

warning

The ESLint rule only checks property names, not CSS shorthand values. Shorthand properties like padding: "8px 16px 8px 0" will not be flagged, even though the four-value syntax maps to top / right / bottom / left (physical). Split them manually:

// ❌ Not caught by ESLint — the 4th value (0) targets physical left
<Box sx={{ padding: "8px 16px 8px 0" }} />

// ✅ Split into logical properties
<Box sx={{ paddingBlock: "8px", paddingInlineStart: 0, paddingInlineEnd: 16 }} />

2. Check TypeScript errors​

Murray's StackStyle type excludes all physical direction properties at compile time. If you use a physical property in an sx prop or any typed style object, TypeScript will report an error.

This works recursively for media queries ($lg, $md, etc.) and pseudo states ($hover, $press, etc.).

// ❌ TypeScript error: 'marginLeft' does not exist in type 'StackStyle'
<Box sx={{ marginLeft: 16 }} />

// ✅ OK
<Box sx={{ marginInlineStart: 16 }} />

3. Manual review​

Some patterns can't be caught automatically:

  • Shadow offsets — use i18n.isRTL() to negate the horizontal offset in RTL
  • translateX animations — negate the value in RTL
  • Directional visuals — flip arrows and chevrons (see Visuals below)
  • Absolute positioning — prefer insetInlineStart / insetInlineEnd, fall back to conditional positioning
  • onLayout coordinates — see onLayout below
  • Third-party native components — see Third-party components below

Testing​

Storybook (easiest)​

  1. Create a story for your component (if one doesn't exist you can use the /storybook-stories Claude skill to generate one)
  2. Open the story in Storybook
  3. Switch the language to Arabic using the language selector in the Storybook toolbar
  4. The entire layout flips to RTL — verify your component looks correct

Checklist​

When testing in RTL, look for:

  • Text aligns to the right (start)
  • Directional icons (arrows, chevrons) point the correct way
  • Spacing and margins are mirrored
  • Text doesn't overflow or get truncated unexpectedly
  • Scroll direction is correct
  • Form fields and labels align properly
  • Modals, dropdowns, and tooltips are positioned correctly
  • Animations move in the expected direction

Good practices​

Flexbox and Grid​

flexDirection: "row" automatically reverses in RTL — items flow from right to left. No changes needed. Use flex-start / flex-end (not left / right) for alignment.

// ✅ Works correctly in both LTR and RTL
<HStack justifyContent="flex-start">{/* Aligns to start: left in LTR, right in RTL */}</HStack>

Visuals​

Directional visuals must point the correct way in RTL.

tip

Murray's Icon component already handles this automatically — directional icons like ArrowLeft are replaced by ArrowRight in RTL and vice-versa. No manual work needed for standard Murray icons.

For cases outside of Murray's Icon component (custom SVGs, images, third-party icons), you need to handle flipping manually:

import { i18n } from "alan-i18n";

// Custom SVG that needs directional awareness
function CustomProgressArrow() {
return <svg style={{ transform: i18n.isRTL() ? "scaleX(-1)" : undefined }}>{/* ... */}</svg>;
}

Not all directional visuals should be flipped, be careful to only flip those that imply direction:

Should flipShould NOT flip
Navigation arrows (←, →)Search icon
Chevrons (‹, ›)Phone icon
Progress indicatorsCheckmark
List bulletsMedia controls (▶️)
Text alignment iconsClock / time icons

Absolute positioning​

Use logical properties:

import { Box } from "murray";

// ✅ Logical properties
<Box sx={{ position: "absolute", insetBlockStart: 0, insetInlineEnd: 0 }} />;

Shadows and transforms​

shadowOffset and translateX don't support logical properties. Use i18n.isRTL():

import { i18n } from "alan-i18n";

const style = {
shadowOffset: { width: i18n.isRTL() ? -2 : 2, height: 2 },
};

// translateX animation
const translateX = i18n.isRTL() ? -100 : 100;
tip

Murray's Box component already negates shadowOffset.width in RTL when you use shadow props. You only need the manual fix for shadows outside of Murray's Box.

onLayout coordinates​

React Native's onLayout callback always returns x relative to the physical left edge, even in RTL. If you use layout measurements to position elements, you must compensate:

import { i18n } from "alan-i18n";

function onLayout(event: LayoutChangeEvent) {
const { x, width } = event.nativeEvent.layout;

// Convert physical x to logical start position
const start = i18n.isRTL() ? containerWidth - x - width : x;
}

Alternatively, use a dynamic property key:

const positionStyle = {
[i18n.isRTL() ? "end" : "start"]: measuredX,
};

Third-party native components without RTL support​

Some third-party native components don't support RTL at all (e.g., native tab bars). A common workaround is to reverse the items and remap indices:

import { i18n } from "alan-i18n";

const items = i18n.isRTL() ? _items.toReversed() : _items;
const selectedIndex = i18n.isRTL() ? items.length - 1 - _selectedIndex : _selectedIndex;

function handleSelect(index: number) {
const realIndex = i18n.isRTL() ? items.length - 1 - index : index;
onSelect(realIndex);
}

Common mistakes​

  1. Using shorthand CSS values — margin: "0 -1px" is not caught by ESLint. Split into marginBlock + marginInline.
  2. Forgetting to negate translateX — animations slide the wrong way in RTL.
  3. Flipping universal icons — don't flip search, checkmark, phone, or media controls.
  4. Using textAlign: "left" in CSS/web — use text-align: start instead.
  5. Hardcoding shadow direction — negate shadowOffset.width in RTL (Murray's Box handles this, but manual shadows don't).
  6. Trusting onLayout x values — they're always physical. Convert for logical positioning.
  7. Assuming all Tamagui components support RTL — some (e.g. Switch) required manual workarounds.
  8. Setting supportsRTL: true in Expo config — Murray uses a config plugin (withDisabledDeviceRTL) to control RTL via I18nManager.forceRTL() only. Setting supportsRTL: true bypasses this and causes the device locale to override the app language.

Need help?​

If you have questions about RTL support, ping @saudi-rtl-support on Slack.

References:

  • Notion documentation on RTL Support
  • MDN — CSS Logical Properties
  • React Native — I18nManager
  • Material Design — Bidirectionality
Edit this page
Previous
Responsive styles
Next
Translations & i18n
  • What is RTL?
  • How Murray handles RTL
    • Global direction
    • alan-i18n API
    • Local direction override
  • CSS logical properties
    • Physical vs logical
    • CSS/Tamagui vs React Native naming
  • Migration guide
    • 1. Run the ESLint autofix
    • 2. Check TypeScript errors
    • 3. Manual review
  • Testing
    • Storybook (easiest)
    • Checklist
  • Good practices
    • Flexbox and Grid
    • Visuals
    • Absolute positioning
    • Shadows and transforms
    • onLayout coordinates
    • Third-party native components without RTL support
  • Common mistakes
  • Need help?