Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect date / time segment order in several components, for RTL languages #4711

Open
lreis opened this issue Jun 26, 2023 · 1 comment · May be fixed by #7423
Open

Incorrect date / time segment order in several components, for RTL languages #4711

lreis opened this issue Jun 26, 2023 · 1 comment · May be fixed by #7423
Assignees

Comments

@lreis
Copy link
Contributor

lreis commented Jun 26, 2023

🐛 Bug Report

The order of the date and time fields is incorrectly displayed by the date/time-related RSP components, for the RTL languages (Arabic, Hebrew).

🤔 Expected Behavior

The date and time field order should follow the same order observed with the values returned by Intl.DateTimeFormat / DateFormatter (@internationalized/date), when rendered in elements with the dir attribute set to"rtl".

The example below (using the options: day: "numeric", month: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short"), illustrates the order for all available fields currently used by all components:

ar-AE he-IL
timezone dayPeriod hour:minute year/month/day timezone hour:minute ,day.month.year
Screenshot 2023-06-25 at 8 42 50 AM Screenshot 2023-06-25 at 8 42 46 AM

😯 Current Behavior

Calendar

with zoned time story

ar-AE he-IL
Screenshot 2023-06-26 at 10 27 27 AM Screenshot 2023-06-26 at 10 27 48 AM

DateField

Date Time Value Zoned story

ar-AE he-IL
Screenshot 2023-06-25 at 9 56 55 AM 248872859-cb445c86-9268-41b7-a26b-47d16b80be3a

DatePicker

Default story

ar-AE he-IL
Screenshot 2023-06-25 at 8 55 02 AM
(سنة = year, شهر = month, يوم = day)
ok (no issue)
248884836-46d0ed95-31e7-4d8b-b3ff-314ed7d21f05
(שנה = year, חודש = month, יום = day)

Date Time Value Zoned story

ar-AE he-IL
Screenshot 2023-06-25 at 8 43 56 AM 248875488-264d0403-e7f5-4a1e-8581-f0a8a94fe6de

DateRangePicker

defaultValue story

ar-AE he-IL
Screenshot 2023-06-26 at 10 40 02 AM
(no issue)
Screenshot 2023-06-26 at 10 41 18 AM
Screenshot 2023-06-26 at 10 40 07 AM
(no issue)
Screenshot 2023-06-26 at 10 41 22 AM

defaultValue, zoned story

ar-AE he-IL
Screenshot 2023-06-25 at 10 07 17 AM Screenshot 2023-06-25 at 10 07 37 AM

RangeCalendar

default story

ar-AE he-IL
Screenshot 2023-06-25 at 10 20 39 AM
ok (no issue)
248888104-d100d8dc-280f-4b3e-a873-55d9d31ea92a

with zoned time story

ar-AE he-IL
Screenshot 2023-06-25 at 10 23 29 AM Screenshot 2023-06-25 at 10 24 40 AM

TimeField

default story

ar-AE he-IL
248888640-c15d42dc-88b1-4a7c-ba1c-52ec60868737 248888675-b6b01bb0-3187-4f9f-b4d4-4b213c190832

💁 Possible Solution

I only looked closely at the DatePicker component code, the actual solution might differ slightly across components.

This seems to be happening because the date and time segment objects are rendered in the exact array order in which they are stored:

https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/datepicker/src/DatePickerField.tsx#L48-L56

While this works fine for LTR languages, for RTL this is a problem because the date and time segments should not be mirrored, e.g.:

  • 17:45 should be displayed as 17:45, not 45:17, and
  • 23.06.2023 (in Hebrew) should be displayed as 23.06.2023 instead of 2023.06.23.

Looking at a more detailed example, when using the DatePicker component with time zones for Hebrew, the object array stores segments in this (logical) order of types:

day literal month literal year literal hour literal minute literal timeZoneName

which is then displayed in the exact mirrored order of types:

timeZoneName literal minute literal hour literal year literal month literal day

The expected result should not mirror every segment, but rather only the segment groups ( date_segments , time_segments , timezone_segment -> timezone_segment , time_segments , date_segments):

timeZoneName literal hour literal minute literal day literal month literal year literal

One potential fix is to split the object array into segment subgroups (i.e. date, time, dayPeriod, timezone), and then force an LTR direction attribute on the date and time segment subgroups only.

Arabic poses an additional problem in that the date-related segments seem to be stored in the wrong logical order (day literal month literal year literal). Because of the way segments are rendered currently, this is not manifesting itself as a problem, but it will be once the underlying problem is addressed. Further investigation is required to identify why this is occurring.

💻 Code Sample

Used the latest storybook for testing

🧢 Your Company/Team

Adobe Globalization team

@lreis lreis changed the title Incorrect date / time field order in several components, for RTL languages Incorrect date / time segment order in several components, for RTL languages Jun 26, 2023
@github-project-automation github-project-automation bot moved this to ✏️ To Groom in RSP Component Milestones Jun 28, 2023
@devongovett
Copy link
Member

Did a small experiment and found that it seems to work as expected automatically if you get rid of display: flex on .react-spectrum-Datepicker-inputContents, and make each segment (.react-spectrum-Datepicker-cell) have display: inline. The placeholder inside each segment (.react-spectrum-Datepicker-placeholder) also seem to mess things up. Setting them to display: none "fixes" it. I guess this works because the Unicode bidi algorithm operates over the entire field as opposed to at the individual segment level.

If that is the only solution, then we'll need to find another way of rendering the placeholders so they reserve space even when there is a value present. The current method won't work with display: inline.

@LFDanLu LFDanLu moved this from ✏️ To Groom to 📋 Waiting for Sprint in RSP Component Milestones Sep 18, 2024
@yihuiliao yihuiliao moved this from 📋 Waiting for Sprint to 🏗 In Progress in RSP Component Milestones Nov 19, 2024
@yihuiliao yihuiliao linked a pull request Dec 6, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In Progress
Development

Successfully merging a pull request may close this issue.

4 participants