Direction
Sets the writing direction for a subtree and exposes it to the components that need to know which way is forward.
Sets the writing direction for a subtree and exposes it to the components that need to know which way is forward. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.
newt-rootimport { Avatar } from "@/registry/bases/newt/ui/avatar"
import { DirectionProvider } from "@/registry/bases/newt/ui/direction"
import { MessageComposer } from "@/registry/bases/newt/ui/message-composer"
import {
MessageGroup,
MessageGroupAuthor,
MessageGroupAvatar,
MessageGroupBody,
MessageGroupContent,
MessageGroupHeader,
MessageGroupTime,
} from "@/registry/bases/newt/ui/message-group"
/*
* The same components as anywhere else, with one attribute above them. Nothing
* here is direction-aware: the logical properties do the work.
*
* Placeholder names only — no real account, and no Discord asset.
*/
export default function DirectionDemo() {
return (
<DirectionProvider
dir="rtl"
className="flex w-full max-w-md flex-col gap-2"
>
<MessageGroup>
<MessageGroupAvatar>
<Avatar>ل</Avatar>
</MessageGroupAvatar>
<MessageGroupBody>
<MessageGroupHeader>
<MessageGroupAuthor>ليلى</MessageGroupAuthor>
<MessageGroupTime dateTime="2026-09-07T12:04">
اليوم 12:04
</MessageGroupTime>
</MessageGroupHeader>
<MessageGroupContent>
كل شيء يعمل من اليمين إلى اليسار.
</MessageGroupContent>
</MessageGroupBody>
</MessageGroup>
<MessageComposer channelName="عام" />
</DirectionProvider>
)
}<script setup lang="ts">
import { Avatar } from "~~/registry/bases/newt/ui/avatar"
import { DirectionProvider } from "~~/registry/bases/newt/ui/direction"
import { MessageComposer } from "~~/registry/bases/newt/ui/message-composer"
import {
MessageGroup,
MessageGroupAuthor,
MessageGroupAvatar,
MessageGroupBody,
MessageGroupContent,
MessageGroupHeader,
MessageGroupTime,
} from "~~/registry/bases/newt/ui/message-group"
/*
* The same components as anywhere else, with one attribute above them. Nothing
* here is direction-aware: the logical properties do the work.
*
* Placeholder names only — no real account, and no Discord asset.
*/
</script>
<template>
<DirectionProvider dir="rtl" class="flex w-full max-w-md flex-col gap-2">
<MessageGroup>
<MessageGroupAvatar>
<Avatar>ل</Avatar>
</MessageGroupAvatar>
<MessageGroupBody>
<MessageGroupHeader>
<MessageGroupAuthor>ليلى</MessageGroupAuthor>
<MessageGroupTime date-time="2026-09-07T12:04">
اليوم 12:04
</MessageGroupTime>
</MessageGroupHeader>
<MessageGroupContent>
كل شيء يعمل من اليمين إلى اليسار.
</MessageGroupContent>
</MessageGroupBody>
</MessageGroup>
<MessageComposer channel-name="عام" />
</DirectionProvider>
</template>Keyboard direction
The provider also sets the direction of the primitives under it: Radix Direction.Provider in React, Reka ConfigProvider in Vue. Arrow keys then follow the reading direction. In this list, ArrowLeft moves to the next tab.
newt-rootimport { DirectionProvider } from "@/registry/bases/newt/ui/direction"
import { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
/*
* The provider also sets the direction of the primitives, so in this
* right-to-left list ArrowLeft moves focus to the next tab.
*/
export default function DirectionTabsDemo() {
return (
<DirectionProvider dir="rtl">
<Tabs defaultValue="one">
<TabsList>
<TabsTrigger value="one">الأول</TabsTrigger>
<TabsTrigger value="two">الثاني</TabsTrigger>
<TabsTrigger value="three">الثالث</TabsTrigger>
</TabsList>
</Tabs>
</DirectionProvider>
)
}<script setup lang="ts">
import { DirectionProvider } from "~~/registry/bases/newt/ui/direction"
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
/*
* The provider also sets the direction of the primitives, so in this
* right-to-left list ArrowLeft moves focus to the next tab.
*/
</script>
<template>
<DirectionProvider dir="rtl">
<Tabs default-value="one">
<TabsList>
<TabsTrigger value="one">الأول</TabsTrigger>
<TabsTrigger value="two">الثاني</TabsTrigger>
<TabsTrigger value="three">الثالث</TabsTrigger>
</TabsList>
</Tabs>
</DirectionProvider>
</template>Installation
npx newtui@latest add directionnpx shadcn@latest add @newtui/directionnpx shadcn-vue@latest add @newtui/directionpnpm dlx newtui@latest add directionpnpm dlx shadcn@latest add @newtui/directionpnpm dlx shadcn-vue@latest add @newtui/directionyarn dlx newtui@latest add directionyarn dlx shadcn@latest add @newtui/directionyarn dlx shadcn-vue@latest add @newtui/directionbunx newtui@latest add directionbunx shadcn@latest add @newtui/directionbunx shadcn-vue@latest add @newtui/directiondeno run -A npm:newtui@latest add directiondeno run -A npm:shadcn@latest add @newtui/directiondeno run -A npm:shadcn-vue@latest add @newtui/directionvlx newtui@latest add directionvlx shadcn@latest add @newtui/directionvlx shadcn-vue@latest add @newtui/directionvp dlx newtui@latest add directionvp dlx shadcn@latest add @newtui/directionvp dlx shadcn-vue@latest add @newtui/directionnubx newtui@latest add directionnubx shadcn@latest add @newtui/directionnubx shadcn-vue@latest add @newtui/directionnlx newtui@latest add directionnlx shadcn@latest add @newtui/directionnlx shadcn-vue@latest add @newtui/directionupx newtui@latest add directionupx shadcn@latest add @newtui/directionupx shadcn-vue@latest add @newtui/direction- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { Direction as DirectionPrimitive } from "radix-ui"
import * as React from "react"
/*
* Every component is written with logical properties, so a right-to-left tree
* needs no per-component override — only a `dir` attribute somewhere above it.
* This is that attribute, plus the context a component reads when it has to
* make a decision the CSS cannot: which side a popover flips to, which arrow
* key advances a list. Radix primitives read their direction from their own
* provider, not from `dir`, so this sets that provider too.
*/
export type Direction = "ltr" | "rtl"
const DirectionContext = React.createContext<Direction>("ltr")
export interface DirectionProviderProps extends React.ComponentProps<"div"> {
dir: Direction
}
const DirectionProvider = React.forwardRef<
HTMLDivElement,
DirectionProviderProps
>(({ dir, children, ...props }, ref) => (
<DirectionContext.Provider value={dir}>
<DirectionPrimitive.Provider dir={dir}>
<div ref={ref} dir={dir} {...props}>
{children}
</div>
</DirectionPrimitive.Provider>
</DirectionContext.Provider>
))
DirectionProvider.displayName = "DirectionProvider"
/**
* The direction the nearest provider set, or `"ltr"` when there is none — the
* same default the document has.
*/
function useDirection(): Direction {
return React.useContext(DirectionContext)
}
export { DirectionProvider, useDirection }<script setup lang="ts">
import { ConfigProvider, injectConfigProviderContext } from "reka-ui"
import { provide, toRef } from "vue"
import { DIRECTION_KEY, type Direction } from "./useDirection"
/*
* Every component is written with logical properties, so a right-to-left tree
* needs no per-component override — only a `dir` attribute somewhere above it.
* This is that attribute, plus the injection a component reads when it has to
* make a decision the CSS cannot: which arrow key advances a list. Reka
* primitives read their direction from `ConfigProvider`, not from `dir`, so
* this sets that provider too.
*
* A `ConfigProvider` does not inherit from the one above it: a prop it is not
* given falls back to its default. So the settings of an outer provider, such
* as the locale and id generator Nuxt UI's `UApp` sets, are passed on, and
* only `dir` changes. With no outer provider, Reka's defaults apply.
*/
const props = defineProps<{ dir: Direction }>()
/*
* `ConfigProvider` is the root and renders only its slot, so attributes such
* as `class` would be dropped there. They go on the `div` instead, as in React.
*/
defineOptions({ inheritAttrs: false })
const parent = injectConfigProviderContext(null)
provide(DIRECTION_KEY, toRef(props, "dir"))
</script>
<template>
<ConfigProvider
:dir="props.dir"
:locale="parent?.locale?.value"
:scroll-body="parent?.scrollBody?.value"
:nonce="parent?.nonce?.value"
:teleport-to="parent?.teleportTo?.value"
:use-id="parent?.useId"
>
<div v-bind="$attrs" :dir="props.dir">
<slot />
</div>
</ConfigProvider>
</template>import { inject, ref, type InjectionKey, type Ref } from "vue"
export type Direction = "ltr" | "rtl"
export const DIRECTION_KEY: InjectionKey<Ref<Direction>> = Symbol("newt-dir")
/**
* The direction the nearest provider set, or `"ltr"` when there is none — the
* same default the document has.
*/
export function useDirection(): Ref<Direction> {
return inject(DIRECTION_KEY, ref<Direction>("ltr"))
}export { default as DirectionProvider } from "./DirectionProvider.vue"
export { DIRECTION_KEY, useDirection, type Direction } from "./useDirection"Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Direction to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Direction to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Direction } from "@/components/ui/direction"
export function Example() {
return <Direction />
}<script setup lang="ts">
import { DirectionProvider } from "@/components/ui/direction"
</script>
<template>
<DirectionProvider />
</template>API reference
DirectionProvider
dir?Direction
Required dir value.
DirectionThe registry exports Direction, DirectionProvider. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.
Accessibility
Preserve the native semantics of the rendered elements and pass through ARIA attributes when the surrounding context needs a label or description. Any interactive child needs a visible focus indicator, and meaning must not rely on colour alone.
Tokens
Direction reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-root.
--newt-dir