Conversation
Resurrects the approach from #6682 with review feedback addressed. In order to support RTL languages like Arabic in the tldraw UI, this PR adds a `useDirection()` hook and updates all Radix UI components and CSS to respect the current locale's text direction. Screenshot: <img width="1430" height="658" alt="Screenshot 2026-03-09 at 10 19 14" src="https://github.com/user-attachments/assets/9b0e91a8-74be-4be3-93b4-caa55662ecc9" /> ### Key changes - **`useDirection()` hook**: Returns `'ltr'` or `'rtl'` from the current translation context. Exported publicly from `@tldraw/tldraw`. - **Container `dir` attribute**: Set on `.tl-container` via `useEffect` so CSS can use `.tl-container[dir='rtl']` selectors (review feedback: set `dir` on container instead of scattering it everywhere). - **Provider reordering**: `TldrawUiTranslationProvider` moved above `TldrawUiTooltipProvider` so tooltips can access direction (review feedback from #6682). - **Radix `dir` prop**: All Radix UI root components use `dir={dir}` instead of hardcoded `dir="ltr"` — dropdown menus, popovers, dialogs, selects, sliders, tooltips, context menus. Context menu trigger keeps `dir="ltr"` since the canvas is always LTR. - **Submenu chevrons**: Flip to `chevron-left` in RTL mode. - **CSS logical properties**: Converted physical properties (`margin-left`, `padding-right`, `text-align: left`, `left`/`right`) to logical equivalents (`margin-inline-start`, `padding-inline-end`, `text-align: start`, `inset-inline-start`/`inset-inline-end`). Added `.tl-container[dir='rtl']` overrides for gradients that can't use logical properties. ### Review feedback from #6682 addressed 1. ✅ Set `dir` on `.tl-container` instead of scattering `dir` attributes 2. ✅ Don't call hooks inline as props — hooks called at component level 3. ✅ Keep popover `align = 'center'` default unchanged 4. ✅ No brittle `width: 15px` on `.tlui-kbd > span` 5. ✅ Use Radix `dir` props instead of CSS `!important` overrides 6. ✅ Context menu trigger uses `dir="ltr"` (canvas is always LTR), Root uses `{dir}` 7. ✅ `TldrawUiTranslationProvider` moved above `TldrawUiTooltipProvider` ### Change type - [x] `feature` ### Test plan 1. `yarn dev` → open localhost:5420 2. Switch language to Arabic (العربية) in user preferences 3. Verify menus open on the correct side 4. Verify context menu positions correctly 5. Verify keyboard shortcuts display correctly in menus 6. Verify page menu layout mirrors 7. Verify submenus have left chevrons 8. Verify dialog titles and buttons respect direction - [x] Unit tests ### API changes - Added `useDirection()` — returns current text direction (`'ltr'` | `'rtl'`) based on locale ### Release notes - Add RTL (right-to-left) support for the tldraw UI when using Arabic and other RTL languages <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches a wide surface area of UI components and CSS, so regressions in menu positioning, animations, and resizing behavior are possible, especially in mixed LTR/RTL embedding scenarios. No auth or data-handling logic changes. > > **Overview** > Adds end-to-end RTL support by deriving a `dir` value from the active translation/locale and propagating it through the UI. > > Introduces `useDirection()` (public) plus a shared `RTL_LANGUAGES` set, sets `dir`/`lang` on the `.tl-container`, and updates Radix-based primitives (menus, popovers, dialogs, selects, sliders, tooltips, context menus) to use `dir={dir}` instead of hardcoded LTR, including flipping submenu chevrons in RTL. > > Updates styling to be direction-aware via CSS logical properties and targeted `.tl-container[dir='rtl']` overrides (e.g., sidebar/layout positioning, toast animations/gradients, watermark placement, and dotcom cookie/sidebar spacing), and reorders providers so tooltips can access translation direction. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5b11d76. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )