Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 7b28f58

Browse files
committed
pass locale via props. use js toLocaleDateString()
1 parent 10ab83c commit 7b28f58

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v3.0.3
44
### Fixed
55
- screen reader support for calendar
6+
- take in props to override browser locale for calendar
67

78
## v3.0.2
89
### Fixed

lib/components/DateTime/Calendar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface CalendarAttributes {
2323
export interface CalendarProps extends React.Props<CalendarComponentType> {
2424
/** Current selected date */
2525
value?: Date | string;
26+
/** i18n locale */
27+
locale?: string;
2628

2729
/** Year to display (otherwise shows the year from value) */
2830
year?: number;
@@ -84,7 +86,6 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
8486

8587

8688
constructor(props: CalendarProps) {
87-
const locale = navigator['userLanguage'] || (navigator.language || 'en-us');
8889
super(props);
8990

9091
if (typeof (this.props.value) === 'string') {
@@ -108,9 +109,9 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
108109
detached: false
109110
};
110111

111-
this.monthNames = getLocalMonths(locale);
112+
this.monthNames = getLocalMonths(this.props.locale);
112113

113-
this.dayNames = getLocalWeekdays(locale);
114+
this.dayNames = getLocalWeekdays(this.props.locale);
114115

115116
this.onPrevMonth = this.onPrevMonth.bind(this);
116117
this.onNextMonth = this.onNextMonth.bind(this);
@@ -280,7 +281,6 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
280281

281282
const curYear = this.state.currentDate.year;
282283
const curMonth = this.state.currentDate.month;
283-
const locale = navigator['userLanguage'] || (navigator.language || 'en-us');
284284

285285
const weekdays = this.dayNames.map(day => {
286286
return (
@@ -325,7 +325,7 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
325325
const date = col.date;
326326
const colMonth = col.month;
327327
const key = `${colMonth}-${date}`;
328-
const ariaLabel = `${date} ${this.monthNames[colMonth]} ${curYear}`;
328+
const ariaLabel = new Date(`${curYear}-${colMonth + 1}-${date}`).toLocaleDateString(this.props.locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
329329

330330
/** Grayed out day from another month */
331331
if (colMonth !== curMonth) {

lib/components/DateTime/DateField.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface DateFieldProps extends React.Props<DateFieldType> {
2424
* Default: true
2525
*/
2626
localTimezone?: boolean;
27+
/** i18n locale */
28+
locale?: string;
2729
/**
2830
* Show Calendar below date picker input
2931
*/
@@ -114,6 +116,7 @@ export const DateField: React.StatelessComponent<DateFieldProps> = (props: DateF
114116
<DatePicker
115117
name={props.name}
116118
initialValue={props.initialValue}
119+
locale={props.locale}
117120
localTimezone={props.localTimezone}
118121
tabIndex={props.tabIndex}
119122
showAbove={props.showAbove}

lib/components/DateTime/DatePicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export interface DatePickerProps extends React.Props<DatePickerType> {
4242
* Default: true
4343
*/
4444
localTimezone?: boolean;
45+
46+
/** i18n locale */
47+
locale?: string;
4548
/**
4649
* Show Calendar below date picker input
4750
*/
@@ -446,6 +449,7 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
446449
className={css('date-picker-calendar')}
447450
year={parsed.year || null}
448451
month={parsed.month - 1}
452+
locale={this.props.locale}
449453
attr={this.props.attr.calendar}
450454
/>
451455
<div className={css('date-picker-dropdown-triangle')}></div>

lib/components/DateTime/DateTimeField.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export interface DateTimeFieldProps extends React.Props<DateTimeFieldType> {
4646
* Default: true
4747
*/
4848
localTimezone?: boolean;
49+
/** i18n locale */
50+
locale?: string;
4951
/**
5052
* Show Calendar below date picker input
5153
*/
@@ -370,6 +372,7 @@ export class DateTimeField extends React.Component<DateTimeFieldProps, Partial<D
370372
tabIndex={this.props.tabIndex}
371373
error={!!this.props.error}
372374
disabled={this.props.disabled}
375+
locale={this.props.locale}
373376
localTimezone={this.props.localTimezone}
374377
showAbove={this.props.showAbove}
375378
format={this.props.format}

0 commit comments

Comments
 (0)