# RTL

How to render the interface right to left for Arabic, Hebrew and other RTL languages.

```vue
<template>
  <div dir="rtl" class="w-full max-w-sm flex flex-col gap-4">
    <NuiInput v-model="name" label="الاسم الكامل" placeholder="مثال: ليلى أحمد" />
    <NuiSelect v-model="city" :options="cities" label="المدينة" />
    <NuiSwitch v-model="news">إرسال الأخبار</NuiSwitch>
    <NuiPagination v-model:page="page" :total="90" />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiInput, NuiPagination, NuiSelect, NuiSwitch, type NuiOption } from '@numior/kit';

const name = ref('');
const city = ref<string | null>('cairo');
const news = ref(true);
const page = ref(2);

const cities: readonly NuiOption<string>[] = [
  { value: 'cairo', label: 'القاهرة' },
  { value: 'dubai', label: 'دبي' },
  { value: 'riyadh', label: 'الرياض' },
];
</script>
```

Put the `dir="rtl"` attribute on `<html>` or on the element that needs RTL. Text in inputs
moves to the right, chevrons and pagination arrows flip, and ArrowLeft and ArrowRight swap.

## Direction in the settings

Pass `dir` to `createNuiConfig` or `provideNuiConfig` when the direction switches at runtime or
the page renders on the server:

```ts
createNuiConfig({ dir: () => (settings.rtl ? 'rtl' : 'ltr') });
```

When the settings have no `dir`, a component takes the nearest `dir` attribute above it, then
the document attribute. When there is no attribute at all, the direction is `ltr`.

## What flips

- Margins, borders and positions set with logical properties: `margin-inline-start`,
  `inset-inline-end`, `border-inline-start`.
- Start and end alignment of popovers and menus, for example `bottom-start`.
- The ArrowLeft and ArrowRight keys in lists, tabs, the tree and the splitter.

Time and number fields stay left to right, as digits are written in RTL texts too.

## Your own component

In your own components, get the direction from `useDirection`, not from `getComputedStyle`. On
the server `useDirection` returns the value from the settings:

```ts
import { useDirection } from '@numior/kit';

const direction = useDirection(root);
const shift = computed(() => (direction.isRtl() ? -offset.value : offset.value));
```

`isRtl()` and `dir()` are functions. Call them inside `computed` so the value updates when the
settings change.
