Layout

Direction.

Sets the reading direction for Radix components below it, so menus, selects and sliders mirror correctly in right to left layouts.

Guestbookltr
Guestbookrtl

Installation#

With the CLI

$npx lanterncn add direction

This also installs the Lantern theme and any Lantern UI components it depends on. The shadcn CLI works directly too: npx shadcn@latest add httptim/lantern-ui/direction. See Installation if your project is not set up yet.

Manually

  1. Install the dependencies

    npm install radix-ui
  2. Copy the source into your project

    components/ui/direction.tsx
    "use client";
    
    import * as React from "react";
    import { Direction } from "radix-ui";
    
    function DirectionProvider({
      dir,
      direction,
      children,
    }: React.ComponentProps<typeof Direction.DirectionProvider> & {
      direction?: React.ComponentProps<typeof Direction.DirectionProvider>["dir"];
    }) {
      return <Direction.DirectionProvider dir={direction ?? dir}>{children}</Direction.DirectionProvider>;
    }
    
    const useDirection = Direction.useDirection;
    
    export { DirectionProvider, useDirection };
  3. Update the import paths to match your project

    The source imports cn from @/lib/utils.

Usage#

import { DirectionProvider, useDirection } from "@/components/ui/direction";
<DirectionProvider dir="rtl">
  <div dir="rtl">
    <App />
  </div>
</DirectionProvider>

The provider only tells Radix components the direction. Also set the dir attribute on the html element or a wrapper so text, flex order and logical utilities like ps-* and start-* flip.

useDirection returns the current direction, handy for flipping icons such as arrows.