Skip to content

Commit 11c4098

Browse files
authored
Fix infinity date picker problem - 51 (#997)
* fix inifinity date picker problem * clean up
1 parent fef7124 commit 11c4098

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

example/src/DatePickerExample.jsx

100644100755
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function DatePickerExample({ theme }) {
1010
const [date, setDate] = React.useState(new Date());
1111
const [date2, setDate2] = React.useState(new Date());
1212
const [date3, setDate3] = React.useState(new Date());
13+
const [date4, setDate4] = React.useState(new Date());
1314

1415
return (
1516
<Container style={{ backgroundColor: theme.colors.background.base }}>
@@ -153,6 +154,20 @@ function DatePickerExample({ theme }) {
153154
leftIconMode={"inset"}
154155
type={"underline"}
155156
/>
157+
<DatePicker
158+
autoDismissKeyboard={true}
159+
disabled={false}
160+
hideLabel={false}
161+
inline={false}
162+
label={"Date"}
163+
leftIconMode={"inset"}
164+
onDateChange={setDate4}
165+
type={"solid"}
166+
date={date4}
167+
format={"mmm d, yyyy hh:MM tt"}
168+
minimumDate={new Date()}
169+
mode={"datetime"}
170+
/>
156171
</Section>
157172
</Container>
158173
);

packages/core/src/components/DatePicker/DatePicker.tsx

100644100755
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable prefer-const */
2-
31
import * as React from "react";
42
import {
53
View,
@@ -268,6 +266,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
268266
backgroundColor,
269267
inputStyle: StyleProp<TextStyle>;
270268

269+
// eslint-disable-next-line
271270
inputTextColor = colors.text.strong;
272271
if (disabled) {
273272
activeColor = colors.border.base;
@@ -285,6 +284,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
285284

286285
const { lineHeight, ...subtitle1 } = typography.subtitle1;
287286

287+
// eslint-disable-next-line
288288
inputStyle = {
289289
paddingVertical: 0,
290290
color: inputTextColor,
@@ -408,18 +408,15 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
408408
const minDate = parseDate(minimumDate);
409409
const maxDate = parseDate(maximumDate);
410410

411-
let newDate = currentDate;
412-
413-
if (minDate && currentDate < minDate) {
414-
newDate = minDate;
415-
}
416-
if (maxDate && currentDate > maxDate) {
417-
newDate = maxDate;
418-
}
411+
const isBeforeMinDate = minDate && currentDate < minDate;
412+
const isAfterMaxDate = maxDate && currentDate > maxDate;
419413

420-
if (newDate !== currentDate) {
421-
setValue(newDate);
422-
onDateChange(newDate);
414+
if (isBeforeMinDate) {
415+
setValue(minDate);
416+
onDateChange(minDate);
417+
} else if (isAfterMaxDate) {
418+
setValue(maxDate);
419+
onDateChange(maxDate);
423420
}
424421
}, [value, minimumDate, maximumDate, onDateChange]);
425422

0 commit comments

Comments
 (0)