Skip to content

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

Open
@atsuo-takahashi

Description

@atsuo-takahashi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions