UI: Set Calendar text direction automatically - #81982
Conversation
|
Size Change: +152 B (0%) Total Size: 7.9 MB 📦 View Changed
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
91dc107 to
2989dc6
Compare
| month={ calendarMonth } | ||
| onMonthChange={ setCalendarMonth } | ||
| locale={ locale } | ||
| dir={ isRTL() ? 'rtl' : 'ltr' } |
There was a problem hiding this comment.
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
Here
Should we preserve the isRTL consulting?
There was a problem hiding this comment.
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!
Follow-up to #81814.
What?
Makes
CalendarandRangeCalendarset their default text direction automatically.Why?
The
en-USformatting fallback made calendars LTR on RTL sites whenlocalewas omitted or unsupported, such asskron Node 20.How?
An explicit
dirstill wins. A supported locale determines direction. Otherwise, the calendars use the WordPress text direction while date formatting continues to fall back toen-US.Consumers that intentionally follow their surrounding interface direction, such as DataViews, continue to pass an explicit
dirindependently of their date-formatting locale.Testing Instructions
CalendarandRangeCalendarstories.localeunset and switch the Storybook RTL toolbar between LTR and RTL. Confirm each calendar follows the toolbar direction.Persian (locale code). Confirm the calendar is RTL.dirtoltr. Confirm the explicit override wins.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.