diff --git a/components/date-picker2/__tests__/index-spec.js b/components/date-picker2/__tests__/index-spec.js index 93e5989378..a63bcadef0 100644 --- a/components/date-picker2/__tests__/index-spec.js +++ b/components/date-picker2/__tests__/index-spec.js @@ -1257,6 +1257,43 @@ describe('Picker', () => { findInput().simulate('keydown', { keyCode: KEYCODE.ENTER }); assert(getStrValue(wrapper) === '12/02/2020'); }); + + // fix https://github.com/alibaba-fusion/next/issues/3006 + it('Support defaultValue for quarter', () => { + let defaultValue = ['2021-Q2', '2021-Q1'] + wrapper = mount( + + ); + assert.deepEqual(getStrValue(), ['2021-Q2', '2021-Q1']); + + defaultValue = ['2021-4-1', '2021-8-1'] + wrapper = mount( + + ); + assert.deepEqual(getStrValue(), ['2021-Q2', '2021-Q3']); + + defaultValue = '2021-Q3' + wrapper = mount( + + ); + assert(getStrValue() === '2021-Q3'); + + defaultValue = '2021-7-1' + wrapper = mount( + + ); + assert(getStrValue() === '2021-Q3'); + }) }); }); diff --git a/components/date-picker2/picker.jsx b/components/date-picker2/picker.jsx index 049f8158d7..8f584d9451 100644 --- a/components/date-picker2/picker.jsx +++ b/components/date-picker2/picker.jsx @@ -220,12 +220,18 @@ class Picker extends React.Component { */ getInitValue = () => { const { props } = this; - const { type, value, defaultValue } = props; + const { type, value, defaultValue, format } = props; let val = type === DATE_PICKER_TYPE.RANGE ? [null, null] : null; val = 'value' in props ? value : 'defaultValue' in props ? defaultValue : val; + // 2024-Q2这类季度字符,dayjs必须传入format才能正常初始化 + const regex = /^(?\d{4})-Q(?[1-4])$/; + if ((type === DATE_PICKER_TYPE.RANGE && val && regex.exec(val[0]) && regex.exec(val[1])) || regex.exec(val)) { + return this.checkValue(val, false, format); + } + return this.checkValue(val); }; diff --git a/package-lock.json b/package-lock.json index f57023d3e0..6d08514679 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10927,9 +10927,9 @@ } }, "node_modules/dayjs": { - "version": "1.11.10", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", - "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" + "version": "1.11.13", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz", + "integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==" }, "node_modules/debug": { "version": "4.3.4", @@ -44523,9 +44523,9 @@ "dev": true }, "dayjs": { - "version": "1.11.10", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", - "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" + "version": "1.11.13", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz", + "integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==" }, "debug": { "version": "4.3.4",