-
Notifications
You must be signed in to change notification settings - Fork 207
Description
react-tailwindcss-datepicker/src/components/Datepicker.tsx
Lines 169 to 185 in bf063fe
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.

Then, narrow window size.

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.