Skip to content

Commit 679e355

Browse files
committed
update logic of how unicode is applied
1 parent 8df5ad6 commit 679e355

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/@react-aria/datepicker/src/useDateSegment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
410410
onKeyDown,
411411
onFocus,
412412
style: {
413-
caretColor: 'transparent'
413+
caretColor: 'transparent',
414+
unicodeBidi: 'isolate-override'
414415
},
415416
// Prevent pointer events from reaching useDatePickerGroup, and allow native browser behavior to focus the segment.
416417
onPointerDown(e) {

packages/@react-spectrum/datepicker/stories/DateField.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const preferences = [
277277
{locale: '', label: 'Default', ordering: 'gregory'},
278278
{label: 'Arabic (Algeria)', locale: 'ar-DZ', territories: 'DJ DZ EH ER IQ JO KM LB LY MA MR OM PS SD SY TD TN YE', ordering: 'gregory islamic islamic-civil islamic-tbla'},
279279
{label: 'Arabic (United Arab Emirates)', locale: 'ar-AE', territories: 'AE BH KW QA', ordering: 'gregory islamic-umalqura islamic islamic-civil islamic-tbla'},
280-
{label: 'Arabic (Egypt)', locale: 'AR-EG', territories: 'EG', ordering: 'gregory coptic islamic islamic-civil islamic-tbla'},
280+
{label: 'Arabic (Egypt)', locale: 'ar-EG', territories: 'EG', ordering: 'gregory coptic islamic islamic-civil islamic-tbla'},
281281
{label: 'Arabic (Saudi Arabia)', locale: 'ar-SA', territories: 'SA', ordering: 'islamic-umalqura gregory islamic islamic-rgsa'},
282282
{label: 'Farsi (Afghanistan)', locale: 'fa-AF', territories: 'AF IR', ordering: 'persian gregory islamic islamic-civil islamic-tbla'},
283283
// {territories: 'CN CX HK MO SG', ordering: 'gregory chinese'},

packages/@react-stately/datepicker/src/useDateFieldState.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
269269

270270
let dateValue = useMemo(() => displayValue.toDate(timeZone), [displayValue, timeZone]);
271271
let timeValue = ['hour', 'minute', 'second'];
272+
let dateSegments = ['day', 'month', 'year'];
273+
let rtlLocale = ['ar-DZ', 'ar-AE', 'ar-EG', 'ar-SA'];
272274
let segments = useMemo(() =>
273275
dateFormatter.formatToParts(dateValue)
274276
.map(segment => {
@@ -282,22 +284,31 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
282284

283285
let value = segment.value;
284286
let place = placeholder;
285-
if (segment.type === 'day' && locale !== 'ar-AE') {
287+
if (dateSegments.length === 3 && dateSegments.includes(segment.type) && !rtlLocale.includes(locale)) {
286288
value = `\u2066${value}`;
287289
place = `\u2066${place}`;
290+
// value = `${value}`;
291+
// place = `${place}`;
288292
} else if (segment.type === 'hour') {
289293
value = `\u2066${value}`;
290294
place = `\u2066${place}`;
291295
// Ideally the unicode (\u2069) would be placed at the end but that seems to cause some issues
292296
// with the background when the rightmost character is focused in Hebrew.
293-
} else if (segment.type === 'year' && locale !== 'ar-AE') {
297+
} else if (dateSegments.length === 1 && dateSegments.includes(segment.type) && !rtlLocale.includes(locale)) {
298+
// value = `${value}`;
299+
// place = `${place}`;
294300
value = `\u2069${value}`;
295301
place = `\u2069${place}`;
296302
} else if (timeValue.includes(granularity) && segment.type === granularity) {
297303
value = `\u2069${value}`;
298304
place = `\u2069${place}`;
305+
299306
}
300307

308+
if (dateSegments.includes(segment.type)) {
309+
dateSegments = dateSegments.filter(item => item !== segment.type);
310+
};
311+
301312
return {
302313
type: TYPE_MAPPING[segment.type] || segment.type,
303314
text: isPlaceholder ? place : value,

0 commit comments

Comments
 (0)