Skip to content

[Bug] Calendar popup direction is only calculated on initial component loading #195

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
atsuo-takahashi opened this issue Aug 29, 2023 · 6 comments

Comments

@atsuo-takahashi
Copy link

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");
}
}
}, []);

Currently, calendar popup direction (left or right) is determined by comparing window center and component center.
However, its calculation is only executed on initial component loading because statements are written within useEffect and second argument array is blank.

This causes the problem when component position changed after its initial loading.

Example

Initial position is right side from window center, so calendar popup direction is left.

popup-fix-1

Then, narrow window size.

popup-fix-2

Page layout is flex box design and component comes to left side when window size become narrow.
On this situation, calendar popup direction is not re-calculated, so its popup direction is still left and this causes users cannot click most part of calendar popup.

Possible solution is calculate direction each time when calendar pops up.

@atsuo-takahashi
Copy link
Author

I opened PR #196

@kingekinge
Copy link

should be provided params to control pop up left or right

@atsuo-takahashi
Copy link
Author

@kingekinge
Thank you for your nice comment!
I also think it would be nice to have params to control horizontal direction left | right | auto

in the PR above, I just fixed auto direction calculation logic.

@akashengagebay
Copy link

akashengagebay commented Oct 13, 2023

@atsuo-takahashi
I am facing an issue , When the calender pops-up the direction is being left in my case

Screenshot from 2023-10-13 19-23-26

but when i checked with offical site it was on the left side .
Screenshot from 2023-10-13 19-23-48

i want it to pop on from the left side .
how can it be changed?
Screenshot from 2023-10-13 19-28-52

@atsuo-takahashi
Copy link
Author

@akashengagebay
There is no way to review your code, so following comment is my guess...

I think your situation is depends on component's horizontal positioning on your page.
i.e. If your DatePicker component is located right side of the page, it pops up to left.
At this moment, this horizontal pop up direction is automatically determined by coordinate (x axis) calculations.

As @kingekinge mentioned above, it would be nice to have an option to select horizontal pop up direction.

@auzanxp
Copy link

auzanxp commented Aug 18, 2024

i tried to hardcode the popup position and its works

  useEffect(() => {
    const popoverElement = document.querySelector(
      '.transition-all.absolute.z-10',
    );
    const arrowElement = document.querySelector(
      '.absolute.z-20.h-4.w-4.rotate-45',
    );

    if (popoverElement) {
      popoverElement.classList.add('right-0');
      popoverElement.classList.remove('left-0');
    }

    if (arrowElement) {
      arrowElement.classList.add('right-0', 'mr-3.5');
    }
  }, [date]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants