Skip to content

Commit 527c98a

Browse files
authored
fix: correctly render dates in hebrew calendar (#7864)
* fix: correctly render dates in hebrew calendar * update logic * add stories with calendars
1 parent e4a90c9 commit 527c98a

File tree

2 files changed

+107
-8
lines changed

2 files changed

+107
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,15 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
385385
};
386386
}
387387

388-
let dateSegments = ['day', 'month', 'year'];
389-
let segmentStyle : CSSProperties = {caretColor: 'transparent'};
388+
let segmentStyle: CSSProperties = {caretColor: 'transparent'};
390389
if (direction === 'rtl') {
391390
// While the bidirectional algorithm seems to work properly on inline elements with actual values, it returns different results for placeholder strings.
392391
// To ensure placeholder render in correct format, we apply the CSS equivalent of LRE (left-to-right embedding). See https://www.unicode.org/reports/tr9/#Explicit_Directional_Embeddings.
393392
// However, we apply this to both placeholders and date segments with an actual value because the date segments will shift around when deleting otherwise.
394-
if (dateSegments.includes(segment.type)) {
395-
segmentStyle = {caretColor: 'transparent', direction: 'ltr', unicodeBidi: 'embed'};
396-
} else if (segment.type === 'timeZoneName') {
397-
// This is needed so that the time zone renders on the left side of the time segments (hour:minute).
398-
// Otherwise, it will render on the right side which is incorrect.
399-
segmentStyle = {caretColor: 'transparent', unicodeBidi: 'embed'};
393+
segmentStyle.unicodeBidi = 'embed';
394+
let format = options[segment.type];
395+
if (format === 'numeric' || format === '2-digit') {
396+
segmentStyle.direction = 'ltr';
400397
}
401398
}
402399

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Content} from '@react-spectrum/view';
1515
import {ContextualHelp} from '@react-spectrum/contextualhelp';
1616
import {DateField} from '../';
1717
import {Heading} from '@react-spectrum/text';
18+
import {Provider} from '@react-spectrum/provider';
1819
import React from 'react';
1920

2021
export default {
@@ -108,3 +109,104 @@ let contextualHelp = (
108109

109110
export const _ContextualHelp = () => <DateField label="Date" contextualHelp={contextualHelp} value={date} />;
110111
export const ContextualHelpSideLabel = () => <DateField label="Date" labelPosition="side" contextualHelp={contextualHelp} value={date} />;
112+
113+
export const ArabicAlgeriaPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
114+
ArabicAlgeriaPreferences.parameters = {
115+
chromaticProvider: {
116+
locales: ['ar-DZ-u-ca-gregory', 'ar-DZ-u-ca-islamic', 'ar-DZ-u-ca-islamic-civil', 'ar-DZ-u-ca-islamic-tbla'],
117+
scales: ['medium'],
118+
colorSchemes: ['light'],
119+
express: false
120+
}
121+
};
122+
123+
export const ArabicUAEPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
124+
ArabicUAEPreferences.parameters = {
125+
chromaticProvider: {
126+
locales: ['ar-AE-u-ca-gregory', 'ar-AE-u-ca-islamic-umalqura', 'ar-AE-u-ca-islamic', 'ar-AE-u-ca-islamic-civil', 'ar-AE-u-ca-islamic-tbla'],
127+
scales: ['medium'],
128+
colorSchemes: ['light'],
129+
express: false
130+
}
131+
};
132+
133+
export const ArabicEgyptPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
134+
ArabicEgyptPreferences.parameters = {
135+
chromaticProvider: {
136+
locales: ['ar-EG-u-ca-gregory', 'ar-EG-u-ca-coptic', 'ar-EG-u-ca-islamic', 'ar-EG-u-ca-islamic-civil', 'ar-EG-u-ca-islamic-tbla'],
137+
scales: ['medium'],
138+
colorSchemes: ['light'],
139+
express: false
140+
}
141+
};
142+
143+
export const ArabicSaudiPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
144+
ArabicSaudiPreferences.parameters = {
145+
chromaticProvider: {
146+
locales: ['ar-SA-u-ca-islamic-umalqura', 'ar-SA-u-ca-gregory', 'ar-SA-u-ca-islamic', 'ar-SA-u-ca-islamic-rgsa'],
147+
scales: ['medium'],
148+
colorSchemes: ['light'],
149+
express: false
150+
}
151+
};
152+
153+
154+
export const HebrewPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
155+
HebrewPreferences.parameters = {
156+
chromaticProvider: {
157+
locales: ['he-IL-u-ca-gregory', 'he-IL-u-ca-hebrew', 'he-IL-u-ca-islamic-civil', 'he-IL-u-ca-islamic-tbla'],
158+
scales: ['medium'],
159+
colorSchemes: ['light'],
160+
express: false
161+
}
162+
};
163+
164+
export const JapanesePreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
165+
JapanesePreferences.parameters = {
166+
chromaticProvider: {
167+
locales: ['ja-JP-u-ca-gregory', 'ja-JP-u-ca-japanese'],
168+
scales: ['medium'],
169+
colorSchemes: ['light'],
170+
express: false
171+
}
172+
};
173+
174+
export const ThaiPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
175+
ThaiPreferences.parameters = {
176+
chromaticProvider: {
177+
locales: ['th-TH-u-ca-buddhist', 'th-TH-u-ca-gregory'],
178+
scales: ['medium'],
179+
colorSchemes: ['light'],
180+
express: false
181+
}
182+
};
183+
184+
export const PersianPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
185+
PersianPreferences.parameters = {
186+
chromaticProvider: {
187+
locales: ['fa-AF-u-ca-persian', 'fa-AF-u-ca-gregory', 'fa-AF-u-ca-islamic-civil', 'fa-AF-u-ca-islamic-tbla'],
188+
scales: ['medium'],
189+
colorSchemes: ['light'],
190+
express: false
191+
}
192+
};
193+
194+
export const IndianPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
195+
IndianPreferences.parameters = {
196+
chromaticProvider: {
197+
locales: ['hi-IN-u-ca-gregory', 'hi-IN-u-ca-indian'],
198+
scales: ['medium'],
199+
colorSchemes: ['light'],
200+
express: false
201+
}
202+
};
203+
204+
export const AmharicPreferences = () => <Provider><DateField label="Date" value={dateTime} /></Provider>;
205+
AmharicPreferences.parameters = {
206+
chromaticProvider: {
207+
locales: ['am-ET-u-ca-gregory', 'am-ET-u-ca-ethiopic', 'am-ET-u-ca-ethioaa'],
208+
scales: ['medium'],
209+
colorSchemes: ['light'],
210+
express: false
211+
}
212+
};

0 commit comments

Comments
 (0)