From 8917b58bd9d312a503d201d1e0acca04f068891d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 23 Jun 2020 21:19:26 +0200 Subject: [PATCH] fix: fix #date-picker shortcuts first click on setting date issue, where the cal view did not changes if no date was set from before --- .../components/date-picker/DatePickerAddon.js | 3 ++- .../components/date-picker/DatePickerRange.js | 1 + .../date-picker/__tests__/DatePicker.test.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/dnb-ui-lib/src/components/date-picker/DatePickerAddon.js b/packages/dnb-ui-lib/src/components/date-picker/DatePickerAddon.js index 000e3b771e6..6c9a212779f 100644 --- a/packages/dnb-ui-lib/src/components/date-picker/DatePickerAddon.js +++ b/packages/dnb-ui-lib/src/components/date-picker/DatePickerAddon.js @@ -95,7 +95,7 @@ export default class DatePickerAddon extends React.PureComponent { } callOnChange({ startDate, endDate, event = null, ...args } = {}) { - this.props.onChange && + if (this.props.onChange) { this.props.onChange( { date: startDate, @@ -105,6 +105,7 @@ export default class DatePickerAddon extends React.PureComponent { }, { hidePicker: false, callOnlyOnChangeHandler: false, ...args } ) + } } render() { diff --git a/packages/dnb-ui-lib/src/components/date-picker/DatePickerRange.js b/packages/dnb-ui-lib/src/components/date-picker/DatePickerRange.js index 1ca64a58a49..781d3d30f85 100644 --- a/packages/dnb-ui-lib/src/components/date-picker/DatePickerRange.js +++ b/packages/dnb-ui-lib/src/components/date-picker/DatePickerRange.js @@ -83,6 +83,7 @@ export default class DatePickerRange extends React.PureComponent { if (state._listenForPropChanges) { if ( !state.views || + (typeof props.startDate !== 'undefined' && !state.startDate) || (props.sync && // 1. check if current start state matches with the new start date ((props.startDate && diff --git a/packages/dnb-ui-lib/src/components/date-picker/__tests__/DatePicker.test.js b/packages/dnb-ui-lib/src/components/date-picker/__tests__/DatePicker.test.js index 95b46b58125..d39e16710ef 100644 --- a/packages/dnb-ui-lib/src/components/date-picker/__tests__/DatePicker.test.js +++ b/packages/dnb-ui-lib/src/components/date-picker/__tests__/DatePicker.test.js @@ -100,6 +100,22 @@ describe('DatePicker component', () => { ).toBe('åååå') }) + it('has to work with shortcuts', () => { + const Comp = mount( + + ) + + Comp.find('button.dnb-input__submit-button__button').simulate('click') + Comp.find('span.dnb-toggle-button') + .at(0) + .find('button.dnb-button') + .simulate('click') + + expect(Comp.find('label.dnb-date-picker__header__title').text()).toBe( + 'mai 2020' + ) + }) + it('has two calendar views', () => { Comp.find('button.dnb-input__submit-button__button').simulate('click') expect(Comp.find('.dnb-date-picker__views').exists()).toBe(true)