Playground

Direction provider

Sets the reading direction (ltr or rtl) once for every Radix-based component below it.

  • Built on radix-ui/Direction
  • 2 parts, named exports
  • Arrow keys follow the reading direction: in rtl, ArrowLeft moves to the next tab, slider step up or toolbar item.
  • Pair it with a dir attribute on html so the stylesheet mirrors layout too.

Import

import '@monoline/css';
import {DirectionProvider} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add direction-provider

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {DirectionProvider, Tabs, TabsContent, TabsList, TabsTrigger} from '@monoline/react';

<div dir="rtl">
  <DirectionProvider dir="rtl">
    <Tabs defaultValue="a">
      <TabsList aria-label="Sections">
        <TabsTrigger value="a">الأول</TabsTrigger>
        <TabsTrigger value="b">الثاني</TabsTrigger>
      </TabsList>
      <TabsContent value="a">محتوى</TabsContent>
      <TabsContent value="b">محتوى آخر</TabsContent>
    </Tabs>
  </DirectionProvider>
</div>

Anatomy

Import the parts you need and nest them like this.

import {DirectionProvider, useDirection} from '@monoline/react';

<DirectionProvider>
  <useDirection />
</DirectionProvider>

Examples

Right to left

Tabs inside a DirectionProvider: ArrowLeft moves to the next tab.

Props

DirectionProviderProps

PropTypeDefaultDescription
dir required"ltr" | "rtl"–Reading direction for everything below: `ltr` or `rtl`.
childrenReactNode–The part of the app that should use this direction.

Accessibility

  • Arrow keys follow the reading direction: in rtl, ArrowLeft moves to the next tab, slider step up or toolbar item.
  • Pair it with a dir attribute on html so the stylesheet mirrors layout too.

Keyboard

KeysAction
Arrow keysFollow the reading direction: in rtl
ArrowLeftMoves to the next tab, slider step up or toolbar item