Skip to content

Commit

Permalink
fix(DatePicker): protect flatpickr in shallow render tests (carbon-de…
Browse files Browse the repository at this point in the history
…sign-system#1389)

* fix(DatePicker): protect flatpickr in shallow render tests

* fix(DatePicker): add comment to describe the Null check
  • Loading branch information
scottdickerson authored and alisonjoseph committed Oct 3, 2018
1 parent e85f04d commit ae100de
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,34 +247,37 @@ export default class DatePicker extends Component {
typeof appendTo === 'string'
? document.querySelector(appendTo)
: appendTo;
this.cal = new flatpickr(this.inputField, {
defaultDate: value,
appendTo: appendToNode,
mode: datePickerType,
allowInput: true,
dateFormat: dateFormat,
locale: l10n[locale],
minDate: minDate,
maxDate: maxDate,
plugins:
datePickerType === 'range'
? [new rangePlugin({ input: this.toInputField })]
: '',
clickOpens: true,
nextArrow: this.rightArrowHTML(),
leftArrow: this.leftArrowHTML(),
onChange: (...args) => {
if (onChange) {
onChange(...args);
}
},
onReady: onHook,
onMonthChange: onHook,
onYearChange: onHook,
onOpen: onHook,
onValueUpdate: onHook,
});
this.addKeyboardEvents(this.cal);
// inputField ref might not be set in enzyme tests
if (this.inputField) {
this.cal = new flatpickr(this.inputField, {
defaultDate: value,
appendTo: appendToNode,
mode: datePickerType,
allowInput: true,
dateFormat: dateFormat,
locale: l10n[locale],
minDate: minDate,
maxDate: maxDate,
plugins:
datePickerType === 'range'
? [new rangePlugin({ input: this.toInputField })]
: '',
clickOpens: true,
nextArrow: this.rightArrowHTML(),
leftArrow: this.leftArrowHTML(),
onChange: (...args) => {
if (onChange) {
onChange(...args);
}
},
onReady: onHook,
onMonthChange: onHook,
onYearChange: onHook,
onOpen: onHook,
onValueUpdate: onHook,
});
this.addKeyboardEvents(this.cal);
}
}
}

Expand Down

0 comments on commit ae100de

Please sign in to comment.