Skip to content

Commit

Permalink
fix: fixed DatePicker selected value is not reset after close panel #…
Browse files Browse the repository at this point in the history
…2387 (#2388)

Co-authored-by: shijia.me <[email protected]>
  • Loading branch information
shijiatongxue and shijiame authored Aug 5, 2024
1 parent 25d6d76 commit 5b1ffe7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
19 changes: 19 additions & 0 deletions cypress/e2e/datePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,4 +858,23 @@ describe('DatePicker', () => {
cy.get('.semi-input').eq(0).should('have.value', '2024-01-24');
cy.get('.semi-input').eq(1).should('have.value', '2024-02-26');
});

it('fixed selected is not update when close panel', () => {
cy.visit('http://localhost:6006/iframe.html?id=datepicker--fixed-controlled&viewMode=story');
cy.get('.semi-input').eq(1).click();
cy.get('.semi-datepicker-day').contains('15')
.then($day => {
$day.trigger('click');
});
cy.get('.semi-popover .semi-datepicker-day-selected-start').contains('8');
cy.get('.semi-popover .semi-datepicker-day-selected-end').contains('15');
cy.get('.semi-input').eq(0).click();
cy.get('.semi-datepicker-day').contains('10')
.then($day => {
$day.trigger('click');
});
cy.get('.semi-input').eq(0).click();
cy.get('.semi-popover .semi-datepicker-day-selected-start').contains('8');
cy.get('.semi-popover .semi-datepicker-day-selected-end').contains('9');
});
});
2 changes: 1 addition & 1 deletion packages/semi-foundation/datePicker/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
*/
resetInnerSelectedStates(willUpdateDates?: Date[]) {
const { value } = this._adapter.getStates();
const needResetCachedSelectedValue = !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
const needResetCachedSelectedValue = isNullOrUndefined(willUpdateDates) || !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
if (needResetCachedSelectedValue) {
this.resetCachedSelectedValue(value);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/semi-ui/datePicker/_story/datePicker.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export {
AutoSplitInput,
FixNeedConfirmControlled,
FixedNaN,
PresetsFunctionType
PresetsFunctionType,
FixedControlled
} from './v2';


Expand Down
15 changes: 15 additions & 0 deletions packages/semi-ui/datePicker/_story/v2/FixedControlled.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { DatePicker } from '@douyinfe/semi-ui';

const App = () => (
<>
<DatePicker
type="dateRange"
defaultPickerValue="2022-08-01"
value={[new Date('2022-08-08'), new Date('2022-08-09')]}
style={{ width: 400 }}
/>
</>
);

export default App;
1 change: 1 addition & 0 deletions packages/semi-ui/datePicker/_story/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export { default as AutoSplitInput } from './AutoSplitInput';
export { default as FixNeedConfirmControlled } from './FixNeedConfirmControlled';
export { default as PresetsFunctionType } from './PresetsFunctionType';
export { default as FixedNaN } from './FixedNaN';
export { default as FixedControlled } from './FixedControlled';

0 comments on commit 5b1ffe7

Please sign in to comment.