added default range set or not flag
This commit is contained in:
parent
33c8b690ef
commit
e1ecaf7a31
@ -76,7 +76,8 @@ export const DateRangePicker1 = ({
|
|||||||
placeholder = "Select date range",
|
placeholder = "Select date range",
|
||||||
className = "",
|
className = "",
|
||||||
allowText = false,
|
allowText = false,
|
||||||
resetSignal, // <- NEW prop
|
resetSignal,
|
||||||
|
defaultRange = true,
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
@ -124,10 +125,9 @@ export const DateRangePicker1 = ({
|
|||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Apply default if empty
|
|
||||||
const currentStart = getValues(startField);
|
const currentStart = getValues(startField);
|
||||||
const currentEnd = getValues(endField);
|
const currentEnd = getValues(endField);
|
||||||
if (!currentStart && !currentEnd) {
|
if (defaultRange && !currentStart && !currentEnd) {
|
||||||
applyDefaultDates();
|
applyDefaultDates();
|
||||||
} else if (currentStart && currentEnd) {
|
} else if (currentStart && currentEnd) {
|
||||||
instance.setDate([
|
instance.setDate([
|
||||||
@ -139,12 +139,11 @@ export const DateRangePicker1 = ({
|
|||||||
return () => instance.destroy();
|
return () => instance.destroy();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Reapply default range on resetSignal change
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (resetSignal !== undefined) {
|
if (defaultRange && resetSignal !== undefined) {
|
||||||
applyDefaultDates();
|
applyDefaultDates();
|
||||||
}
|
}
|
||||||
}, [resetSignal]);
|
}, [resetSignal, defaultRange]);
|
||||||
|
|
||||||
const start = getValues(startField);
|
const start = getValues(startField);
|
||||||
const end = getValues(endField);
|
const end = getValues(endField);
|
||||||
@ -173,3 +172,4 @@ export const DateRangePicker1 = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user