suiss/ui · Component
Direction
A provider that sets the reading direction, left-to-right or right-to-left, for the components inside it.
Direction is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
The direction module provides DirectionProvider and useDirection from the chosen base. DirectionProvider takes a direction of ltr or rtl and makes it available to the primitives below it, so behaviors that depend on direction, such as arrow-key navigation and popup placement, follow the reading direction. useDirection returns the current direction for your own components.
The provider does not set the dir attribute on the page. Set dir on the html element or on a container yourself so that the browser and logical CSS properties flip the layout.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies:
- Copy the source into
components/ui/direction.tsx:
- Update the import paths to match your project.
Usage
Wrap your app, or a subtree, in DirectionProvider with the same direction you set in the dir attribute. Read the value with useDirection when a component needs to adapt, for example to pass it to a dir attribute or to rotate a directional icon.
Examples
Right to left
The same card rendered with direction set to rtl, so its footer buttons appear in reversed order.
Notes
- Pair directional icons with the
rtl:Tailwind variant, for examplertl:rotate-180, so arrows point the right way. - Many components in the library use logical properties such as
ps-,pe-,ms-andme-, which flip automatically underdir="rtl".