Skip to content

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

Closed
@lreis

Description

@lreis

๐Ÿ› 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

Metadata

Metadata

Assignees

Type

No type

Projects

Status

โœ… Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions