From 9d705ffc311cc84ebd33b3cf2a23f1a0e300aaec Mon Sep 17 00:00:00 2001 From: Sergey Kazarinov Date: Sun, 13 Apr 2025 21:37:04 +0500 Subject: [PATCH 1/2] fix(readonly): hide clear button when set readOnly prop --- src/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 8807865a96..68cd0e2202 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1388,9 +1388,11 @@ export default class DatePicker extends Component< clearButtonClassName = "", ariaLabelClose = "Close", selectedDates, + readOnly, } = this.props; if ( isClearable && + !readOnly && (selected != null || startDate != null || endDate != null || From a902e602dec7a46b67202d0f78655e10cc8ec265 Mon Sep 17 00:00:00 2001 From: Sergey Kazarinov Date: Sun, 13 Apr 2025 21:38:07 +0500 Subject: [PATCH 2/2] fix(readOnly): disable click for inline calendar when set readOnly prop --- src/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 68cd0e2202..f91e869ce9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -659,6 +659,7 @@ export default class DatePicker extends Component< event?: React.MouseEvent | React.KeyboardEvent, monthSelectedIn?: number, ) => { + if (this.props.readOnly) return; if (this.props.shouldCloseOnSelect && !this.props.showTimeSelect) { // Preventing onFocus event to fix issue // https://github.com/Hacker0x01/react-datepicker/issues/628 @@ -829,6 +830,7 @@ export default class DatePicker extends Component< // When checking preSelection via min/maxDate, times need to be manipulated via getStartOfDay/getEndOfDay setPreSelection = (date?: Date | null): void => { + if (this.props.readOnly) return; const hasMinDate = isDate(this.props.minDate); const hasMaxDate = isDate(this.props.maxDate); let isValidDateSelection = true;