Direction
Provide left-to-right or right-to-left behavior to Zenos components and hooks.
Direction connects an application’s reading direction to Zenos and the underlying Base UI behavior. Use it for keyboard navigation, popup alignment, sliders, menus, and other interactions that need to distinguish logical start from logical end.
الوصول إلى مساحة العمل
أدخل بياناتك للمتابعة إلى مساحة العمل.
تذكرني
Import
Section titled “Import”import { DirectionProvider, useDirection } from "@zentara-co/zenos-ui";Application direction
Section titled “Application direction”Set the document’s native dir attribute and the provider direction from the same application state. The HTML attribute controls browser layout and text flow; the provider controls direction-aware component behavior.
import { DirectionProvider } from "@zentara-co/zenos-ui"; export function App({ children }: { children: React.ReactNode }) { return ( <html lang="ar" dir="rtl"> <body> <DirectionProvider direction="rtl">{children}</DirectionProvider> </body> </html> );}Zenos does not update document.documentElement automatically. The application owns language selection, persistence, server-rendered attributes, and hydration, so it should keep both values synchronized.
Read the current direction
Section titled “Read the current direction”useDirection returns the nearest provider value. Without a provider it returns ltr.
import { useDirection } from "@zentara-co/zenos-ui"; function DirectionStatus() { const direction = useDirection(); return <span>Current direction: {direction}</span>;}Use this hook when custom interaction behavior changes with direction. Pure layout should usually rely on logical CSS properties and utilities such as start, end, ms, me, ps, and pe.
Scoped direction
Section titled “Scoped direction”Direction can change inside a subsection without changing the entire application. Put the DOM attribute and provider on the same boundary.
<section lang="he" dir="rtl"> <DirectionProvider direction="rtl"> <ConversationPreview /> </DirectionProvider></section>Use an explicit direction for interactive component trees. Reserve dir="auto" for isolated text whose writing direction is not known in advance.
Portals
Section titled “Portals”Place DirectionProvider above dialogs, menus, selects, popovers, tooltips, and other portalled components. Context keeps their positioning and keyboard behavior aligned even when the popup is mounted outside the local DOM subtree. The document-level dir value still controls the portal’s text flow and logical CSS.
DirectionProvider useDirection
API
| Prop | Type | Default | Description |
|---|---|---|---|
direction | ltr | rtl | ltr | Reading direction supplied to Zenos and Base UI behavior. |
children | ReactNode | — | Component tree that inherits the configured direction. |
useDirection() | () => ltr | rtl | — | Returns the nearest provider direction, falling back to ltr. |
Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props,
including className, style, aria-*, and data-*.
Accessibility
Section titled “Accessibility”Set a matching lang attribute so assistive technology uses the correct language and pronunciation. Test focus order, arrow keys, text alignment, mirrored directional icons, and popup placement in both directions. Direction alone does not translate labels or make physical left and right styles logical.
For layout guidance, directional icons, mixed-direction content, and a testing checklist, see the broader RTL foundation guide.