Direction
DirectionProvider and useDirection: tells every component which way the page reads, for Arabic, Hebrew and Persian.
{/* Generated by scripts/build-component-docs.mjs — do not edit. The source is the component folder: guidance.json, the doc block and the props. Change those. */}
DirectionProvider and useDirection: tells every component which way the page reads, for Arabic, Hebrew and Persian.
Import
import { DirectionProvider, useDirection } from "@ir/ui";Watch out
dir="rtl"on<html>is necessary and not sufficient. CSS reads the attribute — logical properties,.rtl-mirror, thertl:variant — but Radix does not look at the DOM. It reads direction from this provider, and without it the arrow keys in Tabs, Radio group, Slider and every menu stay left-to-right, and a submenu opens on the wrong side. Set both, once, at the root:
Props
| Prop | Type | Required | What it does |
|---|---|---|---|
direction | Direction | yes | Which way the page reads. Match the dir attribute on <html>. |
Do and don't
Set dir on <html> and wrap the app in DirectionProvider with the same value.
Don't — Set dir="rtl" on the page and stop there.
CSS reads the attribute; Radix reads the provider. With only the attribute the layout mirrors and the keyboard does not, so the arrow that points at the next tab moves to the previous one.
Provide direction once, at the root, beside the theme.
Don't — Wrap individual components in their own provider.
A page reads one way. A provider halfway down the tree means a portalled menu and the button that opened it can disagree.
Use a logical class (ps-, start-, border-s) or the rtl: variant, and keep the hook for geometry done in script.
Don't — Call useDirection to choose between two classes.
A logical class costs nothing and cannot disagree with the DOM. The hook is for pointer maths, swipe direction and third-party props that take a direction.
Put ltr-island on the element that holds it.
Don't — Let an IP address, a SIP trace, an ID or a metric take the page's direction.
Inside right-to-left text the bidi algorithm reorders punctuation: -5% reads as 5%- and 10.0.0.1:5060 comes apart at the colon.
Mirror what points along the reading direction — chevrons, arrows, panel toggles. Leave check marks, clocks, logos, media controls, charts' time axes and illustrations as they are.
Don't — Mirror every icon and every picture.
A clock running backwards is wrong in every language, and time on a chart runs left to right for everyone who reads monitoring data.
Accessibility
- Direction is half of what a screen reader needs; the other half is lang on <html>. Set both, or Arabic text is read with the wrong voice.
- With the provider in place, arrow-key navigation in Tabs, Radio group, Slider and menus follows the visual order in both directions.
- DirectionProvider renders no element of its own, so it cannot change the accessibility tree.
Where it is drawn
None — direction is a property of the page, not a component in the library