# RTL

Configure Zenos for Arabic, Hebrew, Persian, and mixed-direction product interfaces.

Zenos supports right-to-left interfaces through native HTML direction, logical layout utilities, and the [Direction component](/components/direction/) for interactive Base UI behavior. Set both layers: `dir` controls browser layout and text flow, while `DirectionProvider` keeps keyboard navigation, positioning, sliders, menus, and portalled surfaces aligned with that direction.

```tsx
import { ArrowRightIcon } from "@phosphor-icons/react";
import { Button, Card, DirectionProvider, Field, Input, Stack, Switch, Text } from "@zentara-co/zenos-ui";

function RtlFoundationExample() {
  return (
    <div dir="rtl" lang="ar" className="flex w-full justify-center">
      <DirectionProvider direction="rtl">
        <Card className="w-full max-w-xl text-start">
          <Card.Header>
            <Card.Title>مرحباً بعودتك</Card.Title>
            <Card.Description>أدخل بياناتك للوصول إلى مساحة العمل.</Card.Description>
          </Card.Header>
          <Card.Content>
            <Stack gap="4">
              <Field.Root>
                <Field.Label>البريد الإلكتروني</Field.Label>
                <Field.Control render={<Input type="email" placeholder="name@example.com" />} />
              </Field.Root>
              <div className="flex items-center justify-between gap-4">
                <Text size="s">تذكرني</Text>
                <Switch aria-label="تذكرني" defaultChecked />
              </div>
            </Stack>
          </Card.Content>
          <Card.Footer className="justify-end">
            <Button variant="primary" endIcon={<ArrowRightIcon className="rtl:rotate-180" />}>
              تسجيل الدخول
            </Button>
          </Card.Footer>
        </Card>
      </DirectionProvider>
    </div>
  );
}
```

## Configure the application root

Set the document language and direction as early as possible, ideally in the server-rendered root element. Then wrap the application with Zenos' provider.

```tsx
import { DirectionProvider } from "@zentara-co/zenos-ui";

export function App({ children }: { children: React.ReactNode }) {
  return <DirectionProvider direction="rtl">{children}</DirectionProvider>;
}
```

```html
<html lang="ar" dir="rtl"></html>
```

Use `direction="ltr" | "rtl"` on `DirectionProvider`. The default is `ltr`. Zenos does not change `document.documentElement` for you because applications own language selection, SSR output, persistence, and hydration.

## Scope a mixed-direction region

An application can keep its document LTR while rendering an RTL conversation, preview, or embedded workflow. Keep the DOM attribute and provider on the same boundary:

```tsx
<div lang="he" dir="rtl">
  <DirectionProvider direction="rtl">
    <MessageThread />
  </DirectionProvider>
</div>
```

Plain text can use `dir="auto"` when its direction is unknown, but interactive component trees need an explicit provider direction.

## Write direction-independent layouts

Prefer logical language in application styles and component composition:

| Physical                   | Logical equivalent        |
| -------------------------- | ------------------------- |
| `left-*` / `right-*`       | `start-*` / `end-*`       |
| `ml-*` / `mr-*`            | `ms-*` / `me-*`           |
| `pl-*` / `pr-*`            | `ps-*` / `pe-*`           |
| `border-l` / `border-r`    | `border-s` / `border-e`   |
| `text-left` / `text-right` | `text-start` / `text-end` |

Physical values are still correct when the meaning is genuinely physical—for example, a comparison handle anchored to the left side of an image. Zenos' `Sheet` accepts `inline-start` and `inline-end` for language-aware edges while retaining `left` and `right` for explicitly physical placement.

`AppShell` places Side Nav at inline start and opens its compact navigation sheet from that same edge. Table headings, toggles, switches, pagination, breadcrumbs, submenu indicators, gallery controls, and horizontal resize keyboard behavior also follow direction.

## Directional icons

Mirror arrows and chevrons whose meaning is backward, forward, expand, or collapse. Do not mirror logos, checkmarks, media controls, or icons that depict a physical object.

```tsx
<Button endIcon={<ArrowRightIcon className="rtl:rotate-180" />}>Continue</Button>
```

Built-in Zenos pagination, breadcrumb, menu, and lightbox chevrons mirror automatically. Consumer-provided icons remain under application control because Zenos cannot infer their meaning.

## Portals and overlays

Keep `DirectionProvider` above dialogs, menus, selects, popovers, tooltips, and other portalled components. Base UI uses the context to resolve alignment and keyboard behavior even when the popup is mounted outside the local DOM subtree. The document-level `dir` attribute ensures logical CSS and text alignment also reach the portal container.

Use logical Sheet sides for localized applications:

```tsx
<Sheet.Content side="inline-end">
  <Sheet.Title>Settings</Sheet.Title>
</Sheet.Content>
```

## Fonts and content

Choose a font family with complete glyph coverage for the target language. Keep user-entered identifiers, email addresses, URLs, code, and numbers in their natural direction; use a nested `dir="ltr"` or CSS `unicode-bidi` treatment only for the specific content that needs it.

Translated labels are often longer than their English equivalents. Test narrow containers, zoom, validation messages, loading states, and mixed Arabic or Hebrew text with Latin product names.

## Testing checklist

- Render representative pages with `dir="rtl"` and `DirectionProvider direction="rtl"`.
- Verify arrow-key behavior for sliders, resizable panels, galleries, tabs, menus, and composite controls.
- Open every portalled surface and confirm alignment, entry motion, and close controls.
- Check that Side Nav, leading and trailing icons, table alignment, and form labels follow inline start.
- Test mixed-direction content, long translations, keyboard focus order, screen-reader labels, and browser zoom.
- Run accessibility and visual-regression coverage in both LTR and RTL for critical product flows.

Source: https://zenos-ui.pages.dev/foundations/rtl/