Skip to content

Commit

Permalink
Fixed scroll behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Sep 12, 2024
1 parent e9ee7c3 commit 248afe9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ const DateInputV2: React.FC<Props> = ({
getDayCount(datePickerHeaderDate);
}, [datePickerHeaderDate]);

useEffect(() => {
value && setDatePickerHeaderDate(value);
const scrollTime = (smooth: boolean = true) => {
const timeScrollers = [hourScrollerRef, minuteScrollerRef];
timeScrollers.forEach((scroller) => {
if (!scroller.current) return;
Expand All @@ -268,10 +267,23 @@ const DateInputV2: React.FC<Props> = ({
const toScroll =
selectedPosition - scroller.current.getBoundingClientRect().top;

selected.parentElement?.scrollBy({ top: toScroll, behavior: "smooth" });
selected.parentElement?.scrollBy({
top: toScroll,
behavior: smooth ? "smooth" : "instant",
});
}
});
}, [value, popOverOpen]);
};

useEffect(() => {
value && setDatePickerHeaderDate(value);
scrollTime();
}, [value]);

useEffect(() => {
if (!popOverOpen) return;
scrollTime(false);
}, [popOverOpen]);

useEffect(() => {
isOpen && popoverButtonRef.current?.click();
Expand Down

0 comments on commit 248afe9

Please sign in to comment.