Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disabled cause dead loop #672

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ coverage/
.umi
.umi-production
.umi-test
.env.local
.env.local
.dumi
14 changes: 10 additions & 4 deletions src/hooks/useValueTexts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import shallowEqual from 'shallowequal';
import useMemo from 'rc-util/lib/hooks/useMemo';
import shallowEqual from 'rc-util/lib/isEqual';
import type { GenerateConfig } from '../generate';
import type { CustomFormat, Locale } from '../interface';
import { formatValue } from '../utils/dateUtil';
import { formatValue, isEqual } from '../utils/dateUtil';

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

return [fullValueTexts, firstValueText];
},
[value, formatList],
(prev, next) => prev[0] !== next[0] || !shallowEqual(prev[1], next[1]),
[value, formatList, locale],
(prev, next) =>
// Not Same Date
!isEqual(generateConfig, prev[0], next[0]) ||
// Not Same format
!shallowEqual(prev[1], next[1], true) ||
// Not Same locale
!shallowEqual(prev[2], next[2], true),
);
}
18 changes: 18 additions & 0 deletions tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import type { PanelMode, PickerMode } from '../src/interface';
import { getMoment, isSame, MomentPicker, mount } from './util/commonUtil';
import enUS from '../src/locale/en_US';
import zhCN from '../src/locale/zh_CN';

describe('Picker.Basic', () => {
beforeAll(() => {
Expand Down Expand Up @@ -1043,4 +1045,20 @@ describe('Picker.Basic', () => {

wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
});

it('switch picker locale should reformat value', () => {
const wrapper = mount(
<MomentPicker value={getMoment('2011-11-11')} format={'dddd'} locale={enUS} />,
);
expect(wrapper.find('input').prop('value')).toEqual('Friday');

// Switch locale
moment.locale('zh-cn');
wrapper.setProps({ locale: zhCN });
wrapper.update();
expect(wrapper.find('input').prop('value')).toEqual('星期五');

// Reset locale
moment.locale('en');
});
});
Loading