Skip to content

Commit

Permalink
fix: fix #date-picker shortcuts first click on setting date issue, wh…
Browse files Browse the repository at this point in the history
…ere the cal view did not changes if no date was set from before
  • Loading branch information
tujoworker committed Jun 23, 2020
1 parent 5ea59e6 commit 8917b58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -105,6 +105,7 @@ export default class DatePickerAddon extends React.PureComponent {
},
{ hidePicker: false, callOnlyOnChangeHandler: false, ...args }
)
}
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ describe('DatePicker component', () => {
).toBe('åååå')
})

it('has to work with shortcuts', () => {
const Comp = mount(
<Component shortcuts={[{ title: 'Set date', date: '2020-05-23' }]} />
)

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)
Expand Down

0 comments on commit 8917b58

Please sign in to comment.