Sfoglia il codice sorgente

fix: Fixed the issue that when TimePicker selects a later time first, the invalid time value will be caused when onChangeWithDateFirst is false (#2376)

YannLynn 1 anno fa
parent
commit
066e632904

+ 2 - 0
packages/semi-foundation/timePicker/utils/index.ts

@@ -17,6 +17,8 @@ export const parseToDate = (input: string | Date | number, formatToken = strings
     } else if (typeof input === 'number') {
         return new Date(toNumber(input));
     } else if (typeof input === 'string') {
+        if (input === '') return undefined;
+
         let curDate = new Date();
 
         // console.log(input, formatToken);

+ 33 - 0
packages/semi-ui/timePicker/_story/timepicker.stories.jsx

@@ -374,4 +374,37 @@ export const Fix2082 = () => {
             </div>
         </ConfigProvider>
     );
+};
+
+
+export const Fix2375 = () => {
+  const [dateString, setDateString] = useState();
+  const onChange = (time) => {
+    setDateString(time);
+  };
+
+  return ( 
+    <div>
+      <TimePicker
+        type="timeRange"
+        value={dateString}
+        onChange={onChange}
+        onChangeWithDateFirst={false}
+      /> 
+      <br/>
+      <br/>
+      <Form layout='horizontal' onValueChange={values=>console.log(values)}>
+        <Form.TimePicker
+          rules={[{ required: true, message: '请设置起始时间' }]}
+          //   validate={(fieldValue, values) => validateTimeRange(fieldValue, values)}
+          label="起始时间"
+          width="md"
+          field="time_range"
+          type="timeRange"
+          onChangeWithDateFirst={false}
+          onChange={(...props) => {console.log('props', props)}}
+        />
+      </Form>
+    </div> 
+  );
 };