Skip to content

fix: calculation of calendar popup direction #195 #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/components/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ const Datepicker: React.FC<DatepickerType> = ({
/* End Second */

// UseEffects & UseLayoutEffect
useEffect(() => {
const container = containerRef.current;
const calendarContainer = calendarContainerRef.current;
const arrow = arrowRef.current;

if (container && calendarContainer && arrow) {
const detail = container.getBoundingClientRect();
const screenCenter = window.innerWidth / 2;
const containerCenter = (detail.right - detail.x) / 2 + detail.x;

if (containerCenter > screenCenter) {
arrow.classList.add("right-0");
arrow.classList.add("mr-3.5");
calendarContainer.classList.add("right-0");
}
}
}, []);

useEffect(() => {
if (value && value.startDate && value.endDate) {
const startDate = dayjs(value.startDate);
Expand Down
21 changes: 21 additions & 0 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ const Input: React.FC<Props> = (e: Props) => {
arrow.classList.remove("border-t");
}

if (input && div && arrow) {
const detail = input.getBoundingClientRect();
const screenCenter = window.innerWidth / 2;
const containerCenter = detail.width / 2 + detail.left;
const screenLeftToContainerRight = detail.right;
const calendarWidth = div.getBoundingClientRect().width;

if (
containerCenter > screenCenter &&
screenLeftToContainerRight > calendarWidth
) {
arrow.classList.add("right-0");
arrow.classList.add("mr-3.5");
div.classList.add("right-0");
} else {
arrow.classList.remove("right-0");
arrow.classList.remove("mr-3.5");
div.classList.remove("right-0");
}
}

setTimeout(() => {
div.classList.remove("translate-y-4");
div.classList.remove("opacity-0");
Expand Down