Direction
Tells Sprõut's Base UI parts whether text reads left to right or right to left, so arrow keys, indicators, and popups follow the language on the page.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/direction.jsonCopies Direction into your app, installs the packages, and adds the styles. Then import it from @/components/ui/direction. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
export { DirectionProvider, useDirection, type DirectionProviderProps, type TextDirection, } from '@base-ui/react/direction-provider';Add the styles to your global CSS, after
@import "tailwindcss".Import it from
@/components/ui/direction. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/direction.
Left to right
direction="ltr" with dir="ltr". The path starts on the left.
Right to left
direction="rtl" with dir="rtl". The path starts on the right and the chevron flips.
Keyboard and useDirection
Base UI parts read the provider. In right-to-left text, the left arrow moves to the next view. useDirection returns the same value to your own parts.
useDirection() returns "rtl"
Usage
import { DirectionProvider } from "@tulipfarm/sprout/direction";
<DirectionProvider direction="rtl">
<div dir="rtl">
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/projects">المشاريع</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>الحديقة</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
</div>
</DirectionProvider>direction is "ltr" (the default) or"rtl". The provider renders no element and does not set thedir attribute. Set a matching dir on a wrapping element, or on html for a whole app, so text, layout, and CSS such as the breadcrumb chevron follow the same direction.
Reading the direction
import { useDirection } from "@tulipfarm/sprout/direction";
function NextStepIcon() {
const direction = useDirection();
return direction === "rtl" ? <ArrowLeft /> : <ArrowRight />;
}useDirection() returns the nearest provider's direction, or"ltr" outside one. Use it in your own parts that pick icons or keys by direction.
Accessibility
Arrow keys in toggle groups, tabs, menus, and other composite parts follow the provider: in right-to-left text the left arrow moves to the next item. Focus rings and transitions are those of each part. The provider has no styles or theme tokens of its own.