// preview in
saved for every page

DirectionProvider

Tells the components that the text reads right to left, so sliders, tabs, toolbars and popups follow it. Use it with dir on an element, for Arabic, Hebrew, Persian or Urdu.

Built on Base UIClient componentSource ↗

Installation

Set up Camaleo once (Installation), then import it. It is Base UI's DirectionProvider, re-exported.

import { DirectionProvider } from "@camaleo/react";

You need two things, and they do different jobs:

Anatomy

It renders no element: it only puts the direction in React context. The dir attribute is yours to set.

Examples

The Arabic and Hebrew texts are short sample strings (Save, Cancel, Settings…). Have a native speaker review your real copy.

minimal · light · #3fa34d
40
40

Sliders start on the right

Focus each slider and press the arrows. In RTL the fill grows from the right, Arrow Left raises the value and Arrow Right lowers it, so the key matches the movement.

הגדרות

כללי

Tabs flip their arrow keys

The first tab sits on the right. Arrow Left moves to the next tab; Home and End still go to the first and the last.

Menus in a right-to-left section

Open it. Up and Down don't change. The popup renders in <body>, so pass it dir; it lines up with the trigger's right edge once <html> has dir="rtl".

Welcome back

You have three new messages.

Switch direction at runtime

Flip the switch. Change the provider, dir and lang together, and mirror icons that mean "forward" or "back".

Your changes were saved.

تم حفظ التغييرات.

Logical properties in your CSS

Write padding-inline-start and border-inline-start, not left and right. The same note then works in both directions without a second stylesheet.

رقم الطلب: #A-4821

Left-to-right content inside

Emails, phone numbers and codes read left to right. Give their inputs dir="ltr", and wrap embedded values in <bdi> so they don't reorder the sentence.

In context

Whole pieces of UI in right-to-left languages, in the skin you picked.

الإعدادات

Account settings (Arabic)DirectionProvider · Card · Field · Select · Switch

סיכום הזמנה

סכום ביניים
₪240
משלוח
חינם
סה״כ
₪240
Order summary (Hebrew)DirectionProvider · Card · DataList · Badge · Button

عوامل التصفية

50–300
Price filter (Arabic)DirectionProvider · Card · Slider · Switch · Button

Guidelines

DoSet dir and the provider.

The label, the fill and the arrow keys all agree.

Don’tOnly dir.

It fills from the right, yet Arrow Right raises the value and a click lands on the mirrored spot.

البريد الوارد12

DoLogical margins and padding.

margin-inline-start keeps the gap between the word and the badge in any direction.

البريد الوارد12

Don’tmargin-left in a right-to-left page.

The space lands on the far side and the badge touches the word.

Props

PropTypeDefaultDescription
childrenReactNode—The components that should follow the direction.
direction"ltr" | "rtl"'ltr'The reading direction the components inside follow.

It renders no element, so it takes no other props. Set dir and lang on an element yourself.

Styling hooks

There is nothing to style on the provider itself. The skins use logical properties throughout, so they follow dir; target it when you need a rule for one direction only.

Attributes

dirrtl · ltr, on your element (inherited)
:dir(rtl)CSS pseudo-class that matches the inherited direction
data-orientationhorizontal · vertical, on sliders, tabs and toolbars

Tokens it reads

/* mirror directional icons in right-to-left pages */
:dir(rtl) .icon-forward {
  scale: -1 1;
}

Accessibility

Arrow LeftIn RTL: next tab or toolbar item; raises a slider's value.
Arrow RightIn RTL: previous tab or toolbar item; lowers a slider's value.
Arrow Up / Arrow DownUnchanged: menus, selects and vertical lists don't flip.
Home / EndUnchanged: first and last item, or a slider's minimum and maximum.
Was this page helpful? · Edit this page on GitHub