Skip to content

UI: Set Calendar text direction automatically - #81982

Merged
ciampo merged 6 commits into
trunkfrom
codex/ui-calendar-direction-defaults
Aug 24, 2026
Merged

UI: Set Calendar text direction automatically#81982
ciampo merged 6 commits into
trunkfrom
codex/ui-calendar-direction-defaults

Conversation

@ciampo

@ciampo ciampo commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #81814.

What?

Makes Calendar and RangeCalendar set their default text direction automatically.

Why?

The en-US formatting fallback made calendars LTR on RTL sites when locale was omitted or unsupported, such as skr on Node 20.

How?

An explicit dir still wins. A supported locale determines direction. Otherwise, the calendars use the WordPress text direction while date formatting continues to fall back to en-US.

Consumers that intentionally follow their surrounding interface direction, such as DataViews, continue to pass an explicit dir independently of their date-formatting locale.

Testing Instructions

  1. Open the default Calendar and RangeCalendar stories.
  2. Leave locale unset and switch the Storybook RTL toolbar between LTR and RTL. Confirm each calendar follows the toolbar direction.
  3. In LTR mode, select Persian (locale code). Confirm the calendar is RTL.
  4. Set dir to ltr. Confirm the explicit override wins.
  5. Open the DataViews/FieldTypes date story and switch the toolbar to RTL. Confirm the calendar follows the RTL interface even though its dates remain formatted in English.

Testing Instructions for Keyboard

Focus a day and use the Left and Right Arrow keys. Confirm focus follows the calendar direction in both LTR and RTL modes.

Use of AI Tools

Codex was used to implement and test the change and to draft this pull request description.

@github-actions github-actions Bot added the [Package] UI /packages/ui label Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Size Change: +152 B (0%)

Total Size: 7.9 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 475 kB +74 B (+0.02%)
build/scripts/edit-site/index.min.js 380 kB +23 B (+0.01%)
build/scripts/editor/index.min.js 577 kB +47 B (+0.01%)
build/scripts/media-utils/index.min.js 198 kB +8 B (0%)

compressed-size-action

@ciampo ciampo self-assigned this Aug 24, 2026
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Aug 24, 2026
@ciampo
ciampo marked this pull request as ready for review August 24, 2026 12:36
@ciampo
ciampo requested a review from a team as a code owner August 24, 2026 12:36
@github-actions

github-actions Bot commented Aug 24, 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: simison <simison@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>

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

@ciampo
ciampo force-pushed the codex/ui-calendar-direction-defaults branch from 91dc107 to 2989dc6 Compare August 24, 2026 13:18
@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Aug 24, 2026
@ciampo ciampo changed the title UI: Fix Calendar default text direction UI: Set Calendar text direction automatically Aug 24, 2026
@ciampo
ciampo enabled auto-merge (squash) August 24, 2026 14:51
@ntsekouras
ntsekouras disabled auto-merge August 24, 2026 15:08
month={ calendarMonth }
onMonthChange={ setCalendarMonth }
locale={ locale }
dir={ isRTL() ? 'rtl' : 'ltr' }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems removing the dir from the date controls changes behavior for consumers outside wp-admin. @wordpress/date defaults its locale to en, so when nothing calls wp.date.setSettings (e.g. Storybook), the calendar now takes its direction from en and isRTL() is never consulted. You can see it in Storybook: open the DataViews/FieldTypes date story, toggle the direction in the toolbar and the calendar stays LTR while everything else flips.

Trunk

Image

Here

Image

Should we preserve the isRTL consulting?

@ciampo ciampo Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, it's an angle I hadn't considered.

I restored the explicit dir props in dataviews. Now Calendar keeps its locale-based default, while DataViews intentionally follows the surrounding interface direction independently of its date-formatting locale.

I also added a regression test for the reported case. The DataViews/FieldTypes date story should now follow the RTL toolbar again while keeping its English date formatting.

Thank you for flagging it!

@ntsekouras

Copy link
Copy Markdown
Contributor

@ciampo I disabled the auto-merge because I was reviewing and noticed this.

@ciampo
ciampo enabled auto-merge (squash) August 24, 2026 15:33
@ciampo
ciampo merged commit 8b13d25 into trunk Aug 24, 2026
62 of 63 checks passed
@ciampo
ciampo deleted the codex/ui-calendar-direction-defaults branch August 24, 2026 16:09
@github-actions github-actions Bot modified the milestone: Gutenberg 23.9 Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews [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