Skip to content
  1. Keyline UI
  2. Direction
Keyline UIComponents
  • Get started
    • Installation
    • Theming
    • Modes
    • Configuration
    • Composition
  • Actions
    • Button
    • Button group
    • Split button
    • Toggle
    • Toggle group
    • Toolbar
    • Menu
    • Menubar
    • Context menu
  • Inputs
    • Field and form
    • Checkbox
    • Checkbox group
    • Radio group
    • Switch
    • Slider
    • Segmented
    • Select
    • Native select
    • Combobox
    • Multiselect
    • Number field
    • OTP field
    • Time field
    • Date picker and calendar
    • Date range
  • Data
    • Table
    • Chart
    • Stat and meter
    • Status and badge
    • Progress
    • Skeleton
    • Empty
    • Avatar
    • Kbd
    • Marker
  • Navigation
    • Tabs
    • Breadcrumb
    • Pagination
    • Nav
    • Navigation menu
    • Command menu
  • Overlays
    • Dialog
    • Alert dialog
    • Drawer
    • Sheet
    • Popover
    • Hover card
    • Tooltip
    • Toast
    • Notice
  • Layout
    • App shell
    • Sidebar
    • Panel
    • Resizable
    • Scroll area
    • Accordion
    • Collapsible
    • Carousel
    • Inspector
    • Item
    • Direction
  • Conversation
    • Message
    • Bubble
    • Message scroller
    • Attachment
    • Questionnaire
  • Blocks
    • Shipments

Direction

Sets the writing direction of a subtree in both places Keyline reads it: the DOM's dir, for layout and mirrored glyphs, and Base UI's provider, for which side a tooltip or menu opens on and which way arrow keys go. It adds no box.

Loading the live example…

"use client"

import { useState } from "react"
import { Breadcrumb } from "@/components/keyline/ui/breadcrumb"
import { Button } from "@/components/keyline/ui/button"
import { DirectionProvider } from "@/components/keyline/ui/direction"
import { Pagination } from "@/components/keyline/ui/pagination"
import { Segmented, SegmentedItem } from "@/components/keyline/ui/segmented"
import { Tooltip } from "@/components/keyline/ui/tooltip"

// the same screen in English and in Arabic: the language and the direction change together
const COPY = {
  ltr: { lang: "en", clients: "Clients", client: "Lackawanna County", invoices: "Invoices", pages: "Invoice pages", print: "Print", tip: "Print this page" },
  rtl: { lang: "ar", clients: "العملاء", client: "مقاطعة لاكاوانا", invoices: "الفواتير", pages: "صفحات الفواتير", print: "طباعة", tip: "اطبع هذه الصفحة" },
}

const stay = (e: React.MouseEvent) => e.preventDefault()

export function MirroredInvoices() {
  const [dir, setDir] = useState<"ltr" | "rtl">("rtl")
  const [page, setPage] = useState(3)
  const t = COPY[dir]

  return (
    <div className="grid gap-4">
      <Segmented aria-label="Direction" value={dir} onValueChange={(v: string) => setDir(v as "ltr" | "rtl")} className="justify-self-start">
        <SegmentedItem value="ltr">English · LTR</SegmentedItem>
        <SegmentedItem value="rtl">Arabic · RTL</SegmentedItem>
      </Segmented>
      <DirectionProvider direction={dir} lang={t.lang}>
        <div className="grid gap-4">
          <Breadcrumb
            items={[
              { label: t.clients, render: <a href="?clients" onClick={stay} /> },
              { label: t.client, render: <a href="?client=lackawanna" onClick={stay} /> },
              { label: t.invoices },
            ]}
          />
          <Pagination page={page} pageCount={9} onPageChange={setPage} label={t.pages} />
          <Tooltip content={t.tip} side="inline-end">
            <Button size="compact" className="justify-self-start">
              {t.print}
            </Button>
          </Tooltip>
        </div>
      </DirectionProvider>
    </div>
  )
}

Installation

npx shadcn@latest add @keyline-ui/direction

Run it where your components.json is. The first time, map the @keyline-ui registry: one command, in Installation.

Usage

import { DirectionProvider } from "@/components/keyline/ui/direction"
<DirectionProvider direction="rtl">
  <App />
</DirectionProvider>

Props

PropTypeDefaultDescription
direction"ltr" | "rtl"Default —The direction of everything inside.
useDirection() => "ltr" | "rtl"Default —Reads the direction from Base UI&apos;s provider.

Wrap the app once, or only a region whose language differs from the page. Without it, Keyline still follows the DOM's dir; only the side Base UI places a popup on needs the provider.

Sheet 67 of 73PreviousItemNextMessage
On this page