浏览代码

fix: when using timeZone and disabledHours at the same time in timepicker display value does not meet expectations (#2083)

YannLynn 1 年之前
父节点
当前提交
d7a4270593

+ 9 - 0
cypress/e2e/timePicker.spec.js

@@ -61,4 +61,13 @@ describe('timePicker', () => {
         cy.get('body').click('right');
         cy.get('.semi-input-default').eq(1).should('have.value', '10:24:18');
     });
+
+    it('timezone + disabledHours', () => {
+        cy.visit('http://127.0.0.1:6006/iframe.html?id=timepicker--fix-2082&args=&viewMode=story');
+        cy.get('.semi-input-default').eq(0).click();
+        cy.get('.semi-timepicker-panel-list-hour').eq(0).contains('07').click({ force: true });
+        cy.get('.semi-timepicker-panel-list-minute').eq(0).contains('10').click({ force: true });
+        cy.get('body').click('right');
+        cy.get('.semi-input-default').eq(0).should('have.value', '07:10');
+    });
 });

+ 4 - 1
packages/semi-foundation/timePicker/foundation.ts

@@ -202,8 +202,8 @@ class TimePickerFoundation<P = Record<string, any>, S = Record<string, any>> ext
         const { value, timeZone, __prevTimeZone } = props;
         
         let dates = this.parseValue(value);
-        const invalid = this.validateDates(dates);
 
+        let invalid = dates.some(d => isNaN(Number(d)));
         if (!invalid) {
             if (this.isValidTimeZone(timeZone)) {
                 dates = dates.map(date =>
@@ -213,6 +213,9 @@ class TimePickerFoundation<P = Record<string, any>, S = Record<string, any>> ext
                     )
                 );
             }
+            invalid = dates.some(d =>
+                this.isDisabledHMS({ hours: d.getHours(), minutes: d.getMinutes(), seconds: d.getSeconds() })
+            );
         }
         const inputValue = this.formatValue(dates);
 

+ 20 - 1
packages/semi-ui/timePicker/_story/timepicker.stories.jsx

@@ -1,6 +1,6 @@
 import React, { Component, useState } from 'react';
 import TimePickerPanel from '../index';
-import { TimePicker as BasicTimePicker, Button, Form, Popover } from '../../index';
+import { TimePicker as BasicTimePicker, Button, Form, Popover, ConfigProvider } from '../../index';
 import { strings } from '@douyinfe/semi-foundation/timePicker/constants';
 import { get } from 'lodash';
 
@@ -356,3 +356,22 @@ export const Fix1953 = () => {
     <TimePicker format={'HH'} defaultValue={'10'}/>
   );
 };
+
+export const Fix2082 = () => {
+  const [date, setDate] = useState(new Date());
+    return ( 
+        <ConfigProvider timeZone={10}>
+            <div style={{ width: 300 }}>
+                <h5 style={{ margin: 10 }}>TimePicker:</h5>
+                <TimePicker  
+                  disabledHours={v => [5]}   
+                  format="HH:mm" 
+                  value={date} 
+                  onChange={(date, dateString) => {
+                    console.log('日期', date);
+                    setDate(date)} }
+                />
+            </div>
+        </ConfigProvider>
+    );
+};