feat(core): RTL direction API (useDirection + getLocaleDirection + dir prop)#4269
Open
nynexman4464 wants to merge 1 commit into
Open
feat(core): RTL direction API (useDirection + getLocaleDirection + dir prop)#4269nynexman4464 wants to merge 1 commit into
nynexman4464 wants to merge 1 commit into
Conversation
…r prop) Adds Phase 1 of RTL support: - `direction: 'ltr' | 'rtl'` on InternationalizationContext value - `dir?: 'ltr' | 'rtl'` prop on InternationalizationProvider (overrides locale-derived default) - `useDirection()` hook — returns 'ltr' outside a provider (matches useTranslator fallback pattern) - `getLocaleDirection(locale)` — server-safe helper for RSC / <html dir> - Pagination flips chevron prev/next icons under RTL - Storybook `dir` global toolbar toggle (LTR / RTL) - Pagination `RightToLeft` story - Docs updated with the new API Direction is derived from Intl.Locale.getTextInfo() with try/catch fallback to 'ltr'. Explicit `dir` prop always wins. Ref #4116
nynexman4464
requested review from
cixzhang,
ejhammond,
imdreamrunner and
josephfarina
as code owners
July 23, 2026 21:49
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsPagination · View in Storybook
i18n
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 moderate. Pagination - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Phase 1 of astryx RTL support (refs #4116). Adds the small foundation API — hook, server helper, provider surface — plus Pagination as the reference implementation and a Storybook
Directiontoolbar. Actual component CSS migrations (borders, chevrons, calendar range pills, slider math) land in follow-up PRs.API
Direction is computed via
Intl.Locale.getTextInfo()(CLDR-backed, covers the full RTL BCP 47 tag set —ar,he,fa,ur,ps,sd,yi,ug,dv,ku— not just a hardcoded shortlist). Atry/catchfallback returns'ltr'for exotic runtimes; no polyfill needed on React 19's browser baseline.Design decisions
InternationalizationProvideraccepts bothlocaleand optionaldir. The 99% case islocale="ar"and direction is derived automatically; the 1% case (RTL layout testing under an English catalog, forcing LTR for admin UIs, etc.) uses the explicit override.<html dir>themselves. NouseEffectmutatingdocument.dir— that causes SSR hydration mismatch and misses portaled overlays. This matches every mainstream React library (react-aria, Radix, MUI, Chakra, Ant Design, Mantine, Fluent).setDirection/toggleDirection; consumers manage direction state via their own store or Next.js locale.useDirection()returning the primitive string matches Radix and Mantine's shape.Reference implementation: Pagination
Pagination's prev/next chevron icons now flip under RTL. The aria-labels stay semantic (
@astryx.pagination.previous/@astryx.pagination.next) — only the visual arrow direction changes. ARightToLeftstory demonstrates the behavior.Storybook
New global
Directiontoolbar toggle between LTR and RTL. Wraps every story in<InternationalizationProvider dir={value}>and appliesdir={value}to the story container. Existing decorators (theme, color mode) are unchanged.Docs
packages/cli/docs/internationalization.doc.mjsgains a new "Direction" section coveringuseDirection(),getLocaleDirection(), and thedirprop.Testing
packages/core/src/i18n/__tests__/getLocaleDirection.test.ts— 8 cases:en → ltr,ar/he/fa/ur → rtl,pt-BR/zh-CN → ltr, invalid locale falls back toltr.packages/core/src/i18n/__tests__/useDirection.test.tsx— hook returns provider value; explicitdiroverrides derived; missing provider returnsltr.pnpm --filter '@astryxdesign/core' typecheck: clean.pnpm check:repo: PASS.Follow-ups (not this PR)
Per the RTL migration plan, remaining work: