Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datepicker): pass through flatpickr inline prop #9702

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/react/src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export default class DatePicker extends Component {
onClose,
disable,
enable,
...rest
} = this.props;
if (datePickerType === 'single' || datePickerType === 'range') {
const onHook = (electedDates, dateStr, instance) => {
Expand Down Expand Up @@ -338,6 +339,7 @@ export default class DatePicker extends Component {
// inputField ref might not be set in enzyme tests
if (this.inputField) {
this.cal = new flatpickr(this.inputField, {
inline: rest.inline ?? false,
disableMobile: true,
defaultDate: value,
mode: datePickerType,
Expand Down Expand Up @@ -404,8 +406,17 @@ export default class DatePicker extends Component {
value: prevValue,
disable: prevDisable,
enable: prevEnable,
...prevRest
}) {
const { dateFormat, minDate, maxDate, value, disable, enable } = this.props;
const {
dateFormat,
minDate,
maxDate,
value,
disable,
enable,
...rest
} = this.props;
if (this.cal) {
if (prevDateFormat !== dateFormat) {
this.cal.set({ dateFormat });
Expand All @@ -422,6 +433,9 @@ export default class DatePicker extends Component {
if (enable !== prevEnable) {
this.cal.set('enable', enable);
}
if (rest.inline && rest.inline !== prevRest?.inline) {
this.cal.set('inline', rest.inline);
}
}

// Coordinate when the given `value` prop changes. When this happens, we
Expand Down Expand Up @@ -605,7 +619,8 @@ export default class DatePicker extends Component {
onChange, // eslint-disable-line
locale, // eslint-disable-line
value, // eslint-disable-line
...other
inline, // eslint-disable-line
...rest
} = this.props;

const scope = this.context;
Expand Down Expand Up @@ -668,7 +683,7 @@ export default class DatePicker extends Component {
});
return (
<div className={wrapperClasses}>
<div className={datePickerClasses} {...other}>
<div className={datePickerClasses} {...rest}>
{childrenWithProps}
</div>
</div>
Expand Down