Skip to content

UI: Derive Base UI direction from WordPress i18n - #80399

Merged
ciampo merged 3 commits into
trunkfrom
codex/add-ui-direction-provider
Aug 10, 2026
Merged

UI: Derive Base UI direction from WordPress i18n#80399
ciampo merged 3 commits into
trunkfrom
codex/add-ui-direction-provider

Conversation

@ciampo

@ciampo ciampo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Extracted from #79560.

What?

Makes the direction-sensitive @wordpress/ui components automatically use WordPress's text direction. This covers Autocomplete, Combobox, Popover, Select, Tabs, and Tooltip.

Why?

Base UI defaults its internal direction context to LTR. WordPress already exposes the current text direction through @wordpress/i18n, so consumers should not need to add and forward a second public provider.

How?

  • Adds a private shared wrapper around Base UI's direction provider that reads isRTL().
  • Wraps only the six Root components whose Base UI internals consume direction.
  • Keeps Storybook's existing i18n direction filter and forced remount. The affected components now pick up that value automatically.
  • Updates the Tabs RTL test to verify keyboard behavior without an external provider.

Testing Instructions

  1. Run npm run storybook:dev.
  2. Open a horizontal Tabs story and use the toolbar to switch the direction global between LTR and RTL.
  3. Confirm the selected tab responds to Left Arrow and Right Arrow in the expected direction for each mode.
  4. Open the Popover, Tooltip, Select, Combobox, and Autocomplete stories. Confirm their positioned content follows the direction global without extra provider setup.

Testing Instructions for Keyboard

  1. In the horizontal Tabs story, press Tab until a tab receives focus.
  2. In LTR mode, use Left Arrow and Right Arrow and confirm focus follows the LTR order.
  3. Switch to RTL mode and confirm the same arrow keys follow the reversed RTL order.

Use of AI Tools

This PR was prepared with AI assistance in Codex and reviewed locally.

@github-actions github-actions Bot added the [Package] UI /packages/ui label Jul 17, 2026
@ciampo ciampo mentioned this pull request Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Size Change: +1.07 kB (+0.01%)

Total Size: 7.65 MB

πŸ“¦ View Changed
Filename Size Change
build/modules/boot/index.min.js 49.5 kB +117 B (+0.24%)
build/scripts/block-directory/index.min.js 44.2 kB +111 B (+0.25%)
build/scripts/block-editor/index.min.js 434 kB +152 B (+0.04%)
build/scripts/block-library/index.min.js 357 kB +137 B (+0.04%)
build/scripts/edit-post/index.min.js 52.9 kB +102 B (+0.19%)
build/scripts/edit-site/index.min.js 311 kB +98 B (+0.03%)
build/scripts/editor/index.min.js 510 kB +147 B (+0.03%)
build/scripts/format-library/index.min.js 29.6 kB +77 B (+0.26%)
build/scripts/media-utils/index.min.js 129 kB +127 B (+0.1%)

compressed-size-action

@ciampo ciampo self-assigned this Jul 17, 2026
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Jul 17, 2026
@ciampo
ciampo marked this pull request as ready for review July 17, 2026 08:52
@ciampo
ciampo requested review from a team, ajitbohra, nerrad and ntwb as code owners July 17, 2026 08:52
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 46e00a0.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

πŸ” Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29566702065
πŸ“ Reported issues:

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if we just pre-wrapped all the affected Root subcomponents in wp-ui and hooked in the @wordpress/i18n isRTL() value?

I fear it would be a tall order to ask consumers to set up yet another thing for the package to work. And unlike theming, people will need to be testing specifically for RTL behavior to even notice that it isn't working out of the box.

@jsnajdr jsnajdr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In WordPress we have the @wordpress/i18n imports, even the ui library already uses __. They are mostly used without any reactivity:

import { __, isRTL } from '@wordpress/i18n';

function Compo() {
  return <div className={ isRTL() ? 'r' : 'l' }>{ __( 'Hello' ) }</div>
}

If we export DirectionProvider, we are adding a second API for the same thing. Only the BaseUI components really need this.

Wrapping every BaseUI component with a DirectionProvider is a solution, but it adds a lot of noise to the React tree.

import { DirectionProvider as _DirectionProvider } from '@base-ui/react/direction-provider';
import type { ComponentProps } from 'react';

type DirectionProviderProps = ComponentProps< typeof _DirectionProvider >;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is exported as _DirectionProvider.Props

@ciampo
ciampo force-pushed the codex/add-ui-direction-provider branch from 46e00a0 to fdfde28 Compare August 4, 2026 22:00
@ciampo ciampo changed the title DirectionProvider: Add UI component UI: Derive Base UI direction from WordPress i18n Aug 4, 2026
@ciampo

ciampo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@mirka @jsnajdr is this PR now interpreting your suggestions correctly?

@ciampo
ciampo requested review from jsnajdr and mirka August 4, 2026 22:03

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests well, makes sense πŸ‘

@ciampo
ciampo force-pushed the codex/add-ui-direction-provider branch from fdfde28 to 6263a07 Compare August 10, 2026 15:09
@ciampo
ciampo enabled auto-merge (squash) August 10, 2026 15:13
@ciampo
ciampo merged commit 4762fb7 into trunk Aug 10, 2026
60 checks passed
@ciampo
ciampo deleted the codex/add-ui-direction-provider branch August 10, 2026 15:44
@github-actions github-actions Bot added this to the Gutenberg 23.8 milestone Aug 10, 2026
shail-mehta pushed a commit that referenced this pull request Aug 12, 2026
* DirectionProvider: Add UI wrapper

* DirectionProvider: Add changelog entry

* UI: Derive Base UI direction from i18n

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
@jsnajdr

jsnajdr commented Aug 18, 2026

Copy link
Copy Markdown
Member

is this PR now interpreting your suggestions correctly?

Apologies for a very late reply but yes, I'm pleasantly surprised that the suggestion to wrap everything with DirectionProvider separately turned out to be realistic. There's just a handful of components that really need it πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants