Skip to content

Commit 7db41ef

Browse files
authored
fix: disabled cause dead loop (#672)
* fix: disabled dead loop * chore: clean up
1 parent eb818a0 commit 7db41ef

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ coverage/
3535
.umi
3636
.umi-production
3737
.umi-test
38-
.env.local
38+
.env.local
39+
.dumi

src/hooks/useValueTexts.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import shallowEqual from 'shallowequal';
21
import useMemo from 'rc-util/lib/hooks/useMemo';
2+
import shallowEqual from 'rc-util/lib/isEqual';
33
import type { GenerateConfig } from '../generate';
44
import type { CustomFormat, Locale } from '../interface';
5-
import { formatValue } from '../utils/dateUtil';
5+
import { formatValue, isEqual } from '../utils/dateUtil';
66

77
export type ValueTextConfig<DateType> = {
88
formatList: (string | CustomFormat<DateType>)[];
@@ -36,7 +36,13 @@ export default function useValueTexts<DateType>(
3636

3737
return [fullValueTexts, firstValueText];
3838
},
39-
[value, formatList],
40-
(prev, next) => prev[0] !== next[0] || !shallowEqual(prev[1], next[1]),
39+
[value, formatList, locale],
40+
(prev, next) =>
41+
// Not Same Date
42+
!isEqual(generateConfig, prev[0], next[0]) ||
43+
// Not Same format
44+
!shallowEqual(prev[1], next[1], true) ||
45+
// Not Same locale
46+
!shallowEqual(prev[2], next[2], true),
4147
);
4248
}

tests/picker.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import React from 'react';
99
import { act } from 'react-dom/test-utils';
1010
import type { PanelMode, PickerMode } from '../src/interface';
1111
import { getMoment, isSame, MomentPicker, mount } from './util/commonUtil';
12+
import enUS from '../src/locale/en_US';
13+
import zhCN from '../src/locale/zh_CN';
1214

1315
describe('Picker.Basic', () => {
1416
beforeAll(() => {
@@ -1043,4 +1045,20 @@ describe('Picker.Basic', () => {
10431045

10441046
wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
10451047
});
1048+
1049+
it('switch picker locale should reformat value', () => {
1050+
const wrapper = mount(
1051+
<MomentPicker value={getMoment('2011-11-11')} format={'dddd'} locale={enUS} />,
1052+
);
1053+
expect(wrapper.find('input').prop('value')).toEqual('Friday');
1054+
1055+
// Switch locale
1056+
moment.locale('zh-cn');
1057+
wrapper.setProps({ locale: zhCN });
1058+
wrapper.update();
1059+
expect(wrapper.find('input').prop('value')).toEqual('星期五');
1060+
1061+
// Reset locale
1062+
moment.locale('en');
1063+
});
10461064
});

0 commit comments

Comments
 (0)