Skip to content

Commit d8609b5

Browse files
Merge pull request #5564 from SergeyKazarinov/fix/readOnly
Fix readOnly prop for a clearButton and inline calendare
2 parents 81b5af0 + a902e60 commit d8609b5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ export default class DatePicker extends Component<
659659
event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
660660
monthSelectedIn?: number,
661661
) => {
662+
if (this.props.readOnly) return;
662663
if (this.props.shouldCloseOnSelect && !this.props.showTimeSelect) {
663664
// Preventing onFocus event to fix issue
664665
// https://github.com/Hacker0x01/react-datepicker/issues/628
@@ -829,6 +830,7 @@ export default class DatePicker extends Component<
829830

830831
// When checking preSelection via min/maxDate, times need to be manipulated via getStartOfDay/getEndOfDay
831832
setPreSelection = (date?: Date | null): void => {
833+
if (this.props.readOnly) return;
832834
const hasMinDate = isDate(this.props.minDate);
833835
const hasMaxDate = isDate(this.props.maxDate);
834836
let isValidDateSelection = true;
@@ -1388,9 +1390,11 @@ export default class DatePicker extends Component<
13881390
clearButtonClassName = "",
13891391
ariaLabelClose = "Close",
13901392
selectedDates,
1393+
readOnly,
13911394
} = this.props;
13921395
if (
13931396
isClearable &&
1397+
!readOnly &&
13941398
(selected != null ||
13951399
startDate != null ||
13961400
endDate != null ||

0 commit comments

Comments
 (0)