Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 71f9e7c

Browse files
committed
Fix month name change when language is changed
1 parent 2e0f63b commit 71f9e7c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/components/Calendar/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class Calendar extends PureComponent {
4646
this.dateOptions = { locale: props.locale };
4747
this.styles = generateStyles([coreStyles, props.classNames]);
4848
this.listSizeCache = {};
49-
this.monthNames = [...Array(12).keys()].map(i => props.locale.localize.month(i));
5049
this.isFirstRender = true;
5150
this.state = {
51+
monthNames: [...Array(12).keys()].map(i => props.locale.localize.month(i)),
5252
focusedDate: calcFocusDate(null, props),
5353
drag: {
5454
status: false,
@@ -129,6 +129,9 @@ class Calendar extends PureComponent {
129129
const targetProp = propMapper[this.props.displayMode];
130130
if (prevProps.locale !== this.props.locale) {
131131
this.dateOptions = { locale: this.props.locale };
132+
this.setState({
133+
monthNames: [...Array(12).keys()].map(i => this.props.locale.localize.month(i)),
134+
});
132135
}
133136
if (JSON.stringify(prevProps.scroll) !== JSON.stringify(this.props.scroll)) {
134137
this.setState({ scrollArea: this.calcScrollArea(this.props) });
@@ -137,6 +140,7 @@ class Calendar extends PureComponent {
137140
this.updateShownDate(this.props);
138141
}
139142
}
143+
140144
changeShownDate(value, mode = 'set') {
141145
const { focusedDate } = this.state;
142146
const { onShownDateChange, minDate, maxDate } = this.props;
@@ -191,7 +195,7 @@ class Calendar extends PureComponent {
191195
<select
192196
value={focusedDate.getMonth()}
193197
onChange={e => changeShownDate(e.target.value, 'setMonth')}>
194-
{this.monthNames.map((monthName, i) => (
198+
{this.state.monthNames.map((monthName, i) => (
195199
<option key={i} value={i}>
196200
{monthName}
197201
</option>
@@ -218,7 +222,7 @@ class Calendar extends PureComponent {
218222
</span>
219223
) : (
220224
<span className={styles.monthAndYearPickers}>
221-
{props.monthNames[focusedDate.getMonth()]} {focusedDate.getFullYear()}
225+
{this.state.monthNames[focusedDate.getMonth()]} {focusedDate.getFullYear()}
222226
</span>
223227
)}
224228
{showMonthArrow ? (

0 commit comments

Comments
 (0)