# Story 9.8: RTL/LTR Layout Perfection
## Epic Reference
**Epic 9:** Design & Branding Implementation
## Story Dependencies
- **Story 9.1** (Color System) - Must be complete; RTL audit needs final color variables
- **Story 9.4** (Button Styling) - Buttons must use logical properties
- **Story 9.5** (Form Styling) - Forms require RTL label/error positioning
- **Story 9.6** (Cards & Containers) - Cards need directional border handling
- **Story 9.7** (Navigation & Footer) - Navigation mirroring depends on this work
## User Story
As a **user**,
I want **perfect RTL layout for Arabic and LTR for English**,
So that **the content is natural to read in my language**.
## Background Context
### Current State (from codebase analysis)
The application already has partial RTL support:
- `app()->getLocale()` sets `lang` attribute on ``
- Some logical properties already in use: `border-e`, `me-5`, `rtl:space-x-reverse`
- **Missing:** `dir` attribute is NOT set on `` element
- **Missing:** Systematic RTL audit of all components
### PRD Requirements (Section 4.2)
- Primary Language: Arabic (default) with RTL layout
- Secondary Language: English with LTR layout
- Full site language toggle
- All UI elements in both languages
## Acceptance Criteria
### RTL (Arabic)
- [ ] `dir="rtl"` dynamically set on `` when locale is `ar`
- [ ] Text aligns right naturally
- [ ] Navigation mirrors (sidebar on right for RTL)
- [ ] Form labels on right side of inputs
- [ ] Icons/arrows flip appropriately (chevrons, arrows)
- [ ] Margins/paddings swap using logical properties
### LTR (English)
- [ ] `dir="ltr"` set on `` when locale is `en`
- [ ] Standard left-to-right layout
- [ ] Proper text alignment
### Transitions
- [ ] Seamless language toggle without page reload issues
- [ ] No layout breaks on switch
- [ ] No flash of wrong direction on page load
### Component Support
- [ ] Calendar component RTL support (date picker)
- [ ] Tables RTL support (horizontal scroll direction)
- [ ] Dropdowns open in correct direction
- [ ] Modals position correctly
- [ ] All Flux UI components tested in both modes
## Technical Implementation
### Key Files to Modify
#### 1. Layout Files (Add `dir` attribute)
```
resources/views/components/layouts/app/sidebar.blade.php
resources/views/components/layouts/auth/simple.blade.php
resources/views/components/layouts/auth/card.blade.php
resources/views/components/layouts/auth/split.blade.php
```
**Change:** Update `` tag in each layout:
```blade
```
#### 2. CSS Configuration
```
resources/css/app.css
```
**Add RTL utilities in `@theme` or `@layer`:**
```css
/* RTL-aware icon flipping */
[dir="rtl"] .flip-rtl {
transform: scaleX(-1);
}
/* Force LTR for numbers/code */
.ltr-content {
direction: ltr;
unicode-bidi: embed;
}
```
#### 3. Navigation Component
```
resources/views/components/layouts/app/sidebar.blade.php
```
**Audit and update:**
- Sidebar position (currently uses `border-e` - good)
- Logo placement
- Menu item icons
- Dropdown positions
#### 4. Form Components (Flux UI overrides if needed)
```
resources/views/livewire/auth/*.blade.php
resources/views/livewire/settings/*.blade.php
```
**Ensure all forms use:**
- `text-start` instead of `text-left`
- `ms-*` / `me-*` instead of `ml-*` / `mr-*`
- `ps-*` / `pe-*` instead of `pl-*` / `pr-*`
- `start-*` / `end-*` instead of `left-*` / `right-*`
### Tailwind CSS 4 RTL Approach
Tailwind CSS 4 supports logical properties natively. **Do NOT install a separate RTL plugin.**
**Logical Property Mapping:**
| Physical | Logical (Use This) |
|----------|-------------------|
| `left-*` | `start-*` |
| `right-*` | `end-*` |
| `ml-*` | `ms-*` |
| `mr-*` | `me-*` |
| `pl-*` | `ps-*` |
| `pr-*` | `pe-*` |
| `text-left` | `text-start` |
| `text-right` | `text-end` |
| `border-l-*` | `border-s-*` |
| `border-r-*` | `border-e-*` |
| `rounded-l-*` | `rounded-s-*` |
| `rounded-r-*` | `rounded-e-*` |
**For directional icons that must flip:**
```blade
{{ __('Contact us at') }} info@libra.ps
``` #### Form Validation Errors Ensure error messages appear on the correct side: ```blade