Rettangoli UI supports right-to-left languages such as Arabic, Hebrew, Persian and Urdu. Set the direction once on the document and every primitive and component mirrors itself.
Enabling It
Set dir="rtl" on <html>:
<html lang="ar" dir="rtl">
To switch at runtime, for example when the user changes language, change the same attribute. The page mirrors immediately and open popovers and tooltips move to their new position. No reload or re-render is needed.
document.documentElement.setAttribute("dir", "rtl");
Left to right is the default, so a page without dir needs no change.
Example
An Arabic settings panel. Apart from dir="rtl" on the outer view, which you would normally set on <html>, the markup has no right-to-left attributes of its own: the same markup with English text is a left-to-right panel.
<rtgl-view dir="rtl" lang="ar" d="v" g="lg" w="f" p="lg" bw="xs" bc="bo" br="md">
<rtgl-view d="h" g="md" av="c" w="f">
<rtgl-svg svg="text" wh="16"></rtgl-svg>
<rtgl-text s="lg">إعدادات الحساب</rtgl-text>
</rtgl-view>
<rtgl-view g="sm" w="f">
<rtgl-text s="sm" c="mu">الاسم الكامل</rtgl-text>
<rtgl-input w="f" placeholder="اكتب اسمك هنا..."></rtgl-input>
</rtgl-view>
<rtgl-view d="h" g="sm" wrap>
<rtgl-tag v="pr">نشط</rtgl-tag>
<rtgl-tag pre="text">مسودة</rtgl-tag>
<rtgl-tag removable value="archived">مؤرشف</rtgl-tag>
</rtgl-view>
<rtgl-checkbox checked>أرسل لي إشعارات عبر البريد الإلكتروني</rtgl-checkbox>
<rtgl-view d="h" g="sm" w="f" ah="e">
<rtgl-button v="gh">إلغاء</rtgl-button>
<rtgl-button v="pr" pre="text">حفظ التغييرات</rtgl-button>
</rtgl-view>
</rtgl-view>
Use real text in the page's language when you check a right-to-left layout. English text inside a right-to-left page is reordered around its punctuation, so Save changes. shows as .Save changes and looks like a bug that your users will never see.
What l and r Mean
In Rettangoli attributes, l and r mean the start and end of the reading direction. Under left to right that is left and right. Under right to left they are mirrored. t and b never change.
| Attribute | Left to right | Right to left |
|---|---|---|
ml, pl, bwl |
left side | right side |
mr, pr, bwr |
right side | left side |
mh, ph |
both sides | both sides |
edge="l" |
pinned to the left | pinned to the right |
edge="r" |
pinned to the right | pinned to the left |
place="l", ls, le |
opens to the left of the anchor | opens to the right |
place="r", rs, re |
opens to the right of the anchor | opens to the left |
place="ts", bs |
extends right from the anchor | extends left |
place="te", be |
extends left from the anchor | extends right |
ah="s", ta="s" |
left | right |
ah="e", ta="e" |
right | left |
So a view written once works in both directions. The two rows below use the same attributes; only dir and the text differ:
<rtgl-view d="v" g="md" w="f">
<rtgl-view dir="ltr" d="h" g="md" pl="lg" pv="md" av="c" w="f" bw="xs" bc="bo">
<rtgl-svg svg="text" wh="16"></rtgl-svg>
<rtgl-text>Settings</rtgl-text>
</rtgl-view>
<rtgl-view dir="rtl" lang="ar" d="h" g="md" pl="lg" pv="md" av="c" w="f" bw="xs" bc="bo">
<rtgl-svg svg="text" wh="16"></rtgl-svg>
<rtgl-text>الإعدادات</rtgl-text>
</rtgl-view>
</rtgl-view>
Under left to right the padding is on the left and the icon comes first from the left. Under right to left the padding is on the right and the icon comes first from the right.
The attributes map to CSS logical properties: ml is margin-inline-start, pr is padding-inline-end, bwl is border-inline-start-width, and edge="l" is inset-inline-start: 0.
What Mirrors
- Horizontal rows (
d="h"), alignment (ah), text alignment (ta), and the side attributes in the table above. rtgl-popoverandrtgl-tooltipplacement, and the panels ofrtgl-select,rtgl-tag-select,rtgl-popover-input,rtgl-color-pickerandrtgl-dropdown-menu.- Arrow keys in
rtgl-tabs,rtgl-carouselandrtgl-dropdown-menu: the key that points toward the next item moves to it, so ArrowLeft goes to the next tab. rtgl-carouselslide order, navigation buttons and pager.rtgl-dialogclose button, which sits at the top left.rtgl-sidebarborder and tooltips,rtgl-breadcrumbseparators,rtgl-tablecolumn order, andrtgl-slider.
What Does Not Mirror
rtgl-input-numberandrtgl-input-durationalways show their value left to right, so a minus sign stays in front of the number. The value still lines up with the start edge of the page.- The color area and hue strip of
rtgl-color-picker, andrtgl-waveform, keep their physical orientation. - Images, and icons passed to
rtgl-svg. Mirror a directional icon yourself when it needs it.
Text the User Types
rtgl-input and rtgl-textarea take their direction from their content. Hebrew typed into a field on an English page reads right to left, and English typed into a field on an Arabic page reads left to right. An empty field follows the page, so its placeholder is aligned with the rest of the form.
<rtgl-view g="md" w="320">
<rtgl-input w="f" value="שלום עולם"></rtgl-input>
<rtgl-input w="f" value="مرحبا بالعالم"></rtgl-input>
<rtgl-input w="f" value="Hello world"></rtgl-input>
</rtgl-view>
Keeping a Subtree Physical
Put dir="ltr" on an element to keep everything inside it left to right, whatever the page direction. Use it for content that has a fixed physical layout, such as a code sample, a media timeline or a phone number.
<rtgl-view dir="ltr" d="h" g="md">
<rtgl-text>00:00</rtgl-text>
<rtgl-waveform w="f" h="48"></rtgl-waveform>
<rtgl-text>03:10</rtgl-text>
</rtgl-view>
dir="rtl" on an element works the same way in the other direction.
Custom CSS
In your own styles, use logical properties so they mirror too: margin-inline-start instead of margin-left, inset-inline-end instead of right, and text-align: start instead of text-align: left. Use :dir(rtl) for the cases that need a different rule.