Skip to content

Direction Provider

A context that switches components to right-to-left behavior.

التعليمات التي يتبعها النموذج في كل محادثة.
درجة الحرارة
0.7
hero.tsx

Usage guidelines

  • Set dir as well: DirectionProvider tells components which way the inline axis runs, so arrow keys, slider values and popup placement follow it. In the example above, right to left makes ArrowLeft move to the next tab and raise the slider value. The provider renders no element and does not change CSS. Set the HTML dir attribute on the same subtree, usually on <html>, so layout, logical utilities and :dir() selectors follow.
  • Wrap the app once: Put one provider near the root with the locale's direction. Nest another only for a region written in a different direction from the page.
  • Pass dir to popups in a nested region: Popups render in a portal under <body>, outside the region's dir. Read the direction with useDirection from a component inside the provider and pass it as dir to the content part of every popup in the region, including submenus and popups opened from another popup. A page that sets dir on <html> needs no extra step.
  • Write direction-neutral styles: Use logical utilities such as ps-*, me-*, start-* and text-start for spacing, offsets, borders and alignment, so one class list serves both directions. Caller overrides use the same family, because cn does not merge pl-* with ps-*.
  • Read the direction only when a value must leave CSS: useDirection returns 'ltr' or 'rtl' for code that computes geometry or passes dir to portaled content. Prefer a :dir(rtl) or rtl: variant for anything CSS can express.

Anatomy

tsx
tsx

Examples

Popups in a right-to-left region

Placement and keyboard read the provider, so the submenu opens toward the left and ArrowLeft opens it. Text, logical utilities and :dir() read the DOM instead, and a portaled popup inherits the direction and language of <body>. Each menu here receives dir from useDirection and lang="ar", so its items, submenu chevron and screen-reader language all match the region.

portaled-popup.tsx

API reference

DirectionProvider

Enables RTL behavior for Dify UI and Base UI components. Doesn't render its own HTML element.

Base UI DirectionProvider docs

useDirection

Returns

'ltr' | 'rtl'