- LaralCN-UI: shadcn-style Blade components and blocks you own · part 9 of 26
- Laravel
- Blade
- Tailwindcss
- Frontend
- LaralCN-UI
- RTL
LaralCN-UI right to left: put dir="rtl" on html and everything mirrors
Every LaralCN-UI component and block now mirrors when you set dir="rtl", with no extra setup. Spacing and borders moved to logical utilities and transforms got rtl: flips. The docs gained an Arabic /ar version served by one middleware.
6 min read
LaralCN-UI components were written for left-to-right pages, and an Arabic app had to fix margins by hand after every ui:add. PR #5, merged on 29 Nov 2026, makes every registry component and block mirror when <html dir="rtl"> is set. The docs also gained an /ar version of every page so I could test that claim in a real browser instead of trusting the class names.
Logical utilities in every component
The bulk of the work was mechanical. About 100 physical utilities across 28 files became their logical versions: ml-*/mr-* to ms-*/me-*, pl-*/pr-* to ps-*/pe-*, left-*/right-* to start-*/end-*, plus border-s/border-e, rounded-s/rounded-e and text-start. These follow the document direction on their own, so a button icon with me-2 gets its gap on the correct side in both languages.
I kept physical utilities only where the meaning is physical. left-1/2 -translate-x-1/2 centres something, and centre is the same in both directions. The toast's named positions (top-right and friends) promise a corner of the screen, so they stay put.
Sides that follow the reading direction
Four components take a side: sheet, sidebar, tooltip and hover-card. They now accept start and end, while left and right still pin a physical side for anyone who means it. The sheet shows the pattern:
$sideClasses = match ($side) {
'top' => 'inset-x-0 top-0 h-auto border-b',
'bottom' => 'inset-x-0 bottom-0 h-auto border-t',
'left' => 'inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm',
'right' => 'inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm',
'start' => 'inset-y-0 start-0 h-full w-3/4 border-e sm:max-w-sm',
default => 'inset-y-0 end-0 h-full w-3/4 border-s sm:max-w-sm',
};
The sheet default moved from right to end and the sidebar default from left to start. In a left-to-right page these render exactly as before, so nobody's layout shifted on upgrade. The navbar blocks and sidebar-01 use the logical sides too.
Transforms have no logical form
Tailwind has ms-4 but no translate-x-start. Anything that moves with a transform needs an explicit rtl: variant. The switch thumb is the clearest case:
class="... transition-transform peer-checked:translate-x-[calc(100%-2px)] rtl:peer-checked:-translate-x-[calc(100%-2px)]"
The same treatment went to the sheet and sidebar slides, the sidebar rail (so it stays centred on the panel edge), and the chevrons in pagination, breadcrumb, carousel and the navbar-05 arrow, which get rtl:rotate-180. The progress bar was simpler: rtl:-scale-x-100 on the track mirrors it, so the fill grows from the right while the inline translateX stays the same. The close X does not flip, because an X looks the same both ways.
Each of those classes is written out in full in the source text. Tailwind scans files as plain text, and a class built by string interpolation never compiles. That rule cost me a broken sidebar once already.
Two scripts had to read the direction
Classes cannot fix JavaScript that does arithmetic on positions. The carousel scrolls to the next slide's edge, and in RTL the browser reports scrollLeft as zero at the start and negative values after it. The script now measures edges from the start side and flips the sign back for scrollTo:
var rtl = getComputedStyle(track).direction === 'rtl';
var box = track.getBoundingClientRect();
var scrolled = Math.abs(track.scrollLeft);
var edges = Array.prototype.map.call(track.children, function(item) {
var rect = item.getBoundingClientRect();
return Math.round(scrolled +
(rtl ? box.right - rect.right : rect.left - box.left));
});
// ...
track.scrollTo({ left: rtl ? -target : target, behavior: 'smooth' });
Tabs swap ArrowLeft and ArrowRight in RTL, so the arrow that points toward the next tab moves to it.
Dialogs lost their direction on the way to body
This one surprised me. dialog and alert-dialog move themselves to <body> before showModal(), and so does sheet, because the top layer does not rescue a dialog whose ancestor is display: none. A dialog inside a dir="rtl" section would land in a left-to-right body and open the wrong way round, close button on the wrong side. They now copy direction and language before the move:
if (dialog.parentElement !== document.body) {
if (!dialog.dir) dialog.dir = getComputedStyle(dialog.parentElement).direction;
var lang = dialog.parentElement.closest('[lang]');
if (!dialog.lang && lang) dialog.lang = lang.lang;
document.body.appendChild(dialog);
}
An /ar version of the docs from one middleware
To check all of this I needed RTL pages, so every docs URL now has an Arabic twin: /ar/components/button. I did not want to register every route twice, because the VPS runs route:cache. A global middleware, LocalePrefix, runs before routing instead. It strips a known prefix and sets the locale, then makes route() and url() add the prefix back:
app()->setLocale($segment);
URL::formatPathUsing(fn(string $path) => '/' . $segment . rtrim($path, '/'));
$stripped = substr($request->getPathInfo(), strlen($segment) + 1) ?: '/';
asset() is untouched, so the Vite build still loads from the root. Languages live in config/docs.php, and adding an entry there gives the language its URL prefix and its lang and dir on <html>, plus a link in the switcher.
IBM Plex Sans Arabic loads as --font-arabic and applies through :lang(ar). Code blocks stay left to right on RTL pages. The sidebar footer gained EN and ع links plus the theme toggle, which moved out of the header and is now remembered in localStorage by a small script that runs before first paint. The page text itself stayed English in this PR.
Tests: the package suite went to 130 passing, with a new case for the sheet and sidebar defaults and a tooltip end side. The website suite has 15, including a new LocalePrefixTest. I also checked in Chrome under RTL: switch, progress, carousel scrolling, sheet sides, tab keys and the sidebar-01 collapse in both directions.
Where it is
composer require --dev safi/laralcn-ui
php artisan ui:init
php artisan ui:add sheet
Component changes ship through the registry, so re-run ui:add for components you installed before 29 Nov 2026 to get the RTL versions. No CLI release was needed. English docs live at https://laralcn-ui.abdulkadersafi.com and every page has an Arabic twin under /ar, for example /ar/components/sheet. The code is at https://github.com/Abdulkader-Safi/LaralCN-UI, MIT licensed.
Next: the deploy of this work, where the live site kept serving the old PHP and I found a fourth way a deploy can lie to you.
Last updated 1 Dec 2026 · filed under Laravel, blade, tailwindcss, frontend, laralcn-ui, rtl