Skip to content

React RTL Support and Localisation

React RTL support in SheenUI needs no provider: components follow dir on the html element or any wrapper, so tab pills, arrow keys and drawers mirror, strings come from a partial labels prop and dates and numbers follow a locale prop.

A right-to-left wrapper

Everything inside follows dir: the tab pill, the page arrows and the keyboard (Left and Right swap).

إحصاءات مساحة العمل.

How a component learns the direction

Every component that mirrors itself asks one internal hook, useResolvedDirection in hooks/use-direction.ts. It checks, in order, a direction prop, Base UI’s DirectionProvider, the nearest ancestor with a dir attribute and finally <html dir>. On the server it answers ltr. One shared MutationObserver watches dir, so flipping it at runtime re-renders only the components that care. The hook is not exported from @sheenui/theme; you set dir and the components do the rest.

Key handlers do not subscribe. They call isRtlAt(element), one computed-style read at the moment of the key press, which is why the arrow keys of Tabs and Calendar swap their meaning in right-to-left text. The repo’s own lint rule, sheen/no-direction-detection, rejects any other way of reading the direction, so a new component cannot quietly bypass it.

Portalled surfaces (a Drawer, the Toaster) sit under <body>, so no wrapper above them can set the direction. They follow Base UI’s provider or <html dir>. For an app that is right-to-left throughout, put dir="rtl" on html and nothing else is needed.

Logical sides

Props name sides by reading order, not by screen edge, wherever a screen edge is not what you mean. align on Popover, Tooltip, HoverCard and Menu is start, center or end. Menu’s side also takes inline-start and inline-end. Drawer takes side="start" or "end", and the Toaster accepts position="top-end", where start is the left corner in ltr and the right corner in rtl. The physical values (left, right) remain for the cases that really are about the screen, such as a toast pinned to the bottom-right.

Inside the components the CSS follows the same rule: logical utilities such as ps-*, me-* and text-end, never pl-* or text-right. Write your own code that way and it mirrors for free.

Translate the strings

labels takes a partial object over defaultPaginationLabels. Functions get the numbers, so word order stays yours.

Strings live in labels

A component never hard-codes a string that is rendered or announced. Each one exports a type, such as PaginationLabels, and its English defaults, defaultPaginationLabels. The labels prop is Partial of that type, merged over the defaults, so you translate only what you use. Plain strings stay strings; anything with a number in it is a function, which keeps plurals and word order in your hands. The defaults are plain data with no DOM access, so they are safe to read while prerendering.

<Pagination labels={{ ...defaultPaginationLabels, next: "Weiter" }} pageCount={20} />

Charts follow the same pattern (defaultBarChartLabels holds the keyboard hint and the tooltip’s total and previous-period names), as do the date pickers, the carousel and the side drawer. There is no global i18n provider by design: the strings belong to the component that shows them, so you can load only the languages a screen needs.

Dates and numbers

locale picks the month names, the first weekday and the digits; the chart's default number format follows its own locale.

Locale-aware components

Text that comes from the language rather than from you is formatted with Intl in the locale you pass. Calendar and the date pickers take a BCP 47 locale: month and weekday names, the first day of the week (override it with weekStartsOn) and even the digits follow it, so ar-EG starts on Saturday in Arabic digits. Without one they use the browser’s, so on a prerendered page pass locale and a fixed today to keep the server and client markup equal.

Charts take locale for the default number format: compact values and axis ticks keep the decimals a step needs, so 0.25 stays 0,25 in German. For anything else pass format, a function from number to text. WorldMap reads country names from Intl.DisplayNames in its locale, and its keyboard type-to-find matches in that locale too. See date picker, calendar and world map.

Charts and direction

Charts read the direction through useChartDirection, which wraps the same hook. Their keyboard swaps Left and Right, and plots with a time or bin axis, such as the histogram, mirror themselves. Some charts, the Marimekko among them, deliberately draw left to right in every language so a share axis never flips under its numbers. Numerals and Latin text inside a right-to-left page keep their own direction: wrap an inline value in <bdi> when you mix them in your own markup.

Frequently asked questions

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published .