From d8571795ac0d9a438c18312af2d250f7c18fded9 Mon Sep 17 00:00:00 2001 From: Rafael Tavares <26308880+Rafatcb@users.noreply.github.com> Date: Sat, 25 Nov 2023 19:14:03 -0300 Subject: [PATCH] Disable clear button when the component is disabled --- src/index.jsx | 36 +++++++++++++++++++-------------- src/stylesheets/datepicker.scss | 9 +++++++++ test/datepicker_test.test.js | 17 ++++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/index.jsx b/src/index.jsx index 83367c456..8f150bf60 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -360,10 +360,10 @@ export default class DatePicker extends React.Component { this.props.openToDate ? this.props.openToDate : this.props.selectsEnd && this.props.startDate - ? this.props.startDate - : this.props.selectsStart && this.props.endDate - ? this.props.endDate - : newDate(); + ? this.props.startDate + : this.props.selectsStart && this.props.endDate + ? this.props.endDate + : newDate(); // Convert the date from string format to standard Date format modifyHolidays = () => @@ -384,8 +384,8 @@ export default class DatePicker extends React.Component { minDate && isBefore(defaultPreSelection, startOfDay(minDate)) ? minDate : maxDate && isAfter(defaultPreSelection, endOfDay(maxDate)) - ? maxDate - : defaultPreSelection; + ? maxDate + : defaultPreSelection; return { open: this.props.startOpen || false, preventFocus: false, @@ -1175,14 +1175,14 @@ export default class DatePicker extends React.Component { typeof this.props.value === "string" ? this.props.value : typeof this.state.inputValue === "string" - ? this.state.inputValue - : this.props.selectsRange - ? safeDateRangeFormat( - this.props.startDate, - this.props.endDate, - this.props, - ) - : safeDateFormat(this.props.selected, this.props); + ? this.state.inputValue + : this.props.selectsRange + ? safeDateRangeFormat( + this.props.startDate, + this.props.endDate, + this.props, + ) + : safeDateFormat(this.props.selected, this.props); return React.cloneElement(customInput, { [customInputRef]: (input) => { @@ -1216,6 +1216,7 @@ export default class DatePicker extends React.Component { renderClearButton = () => { const { isClearable, + disabled, selected, startDate, endDate, @@ -1230,7 +1231,12 @@ export default class DatePicker extends React.Component { return (