Skip to content
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
20 changes: 1 addition & 19 deletions src/components/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,7 @@ 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
25 changes: 17 additions & 8 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,28 @@ const Input: React.FC<Props> = (e: Props) => {

function showCalendarContainer() {
if (arrow && div && div.classList.contains("hidden")) {

div.classList.remove("hidden");
div.classList.add("block");

// window.innerWidth === 767
const popoverOnUp = popoverDirection == "up";
const popoverOnDown = popoverDirection === "down";
if (
popoverOnUp ||
const popoverOnDown = popoverDirection === "down";
const calendarPosition = div.getBoundingClientRect();
const body = document.querySelector('body')!;
const bodyPosition = body.getBoundingClientRect();
const calcPosition = Math.ceil(calendarPosition.right - bodyPosition.right);
const finalPosition = calcPosition > 0 ? calcPosition : 0;
const leftPositionCalendar = `left:-${finalPosition}px`;
const leftPositionArrow = `left:${finalPosition}px`;
if(((calendarPosition.right > bodyPosition.right) || (calendarPosition.left < bodyPosition.left)) && window.innerWidth > 767) {
div.setAttribute("style",leftPositionCalendar);
arrow.setAttribute("style",leftPositionArrow);
}

if (popoverOnUp ||
(window.innerWidth > 767 &&
window.screen.height - 100 < div.getBoundingClientRect().bottom &&
!popoverOnDown)
) {
window.screen.height - 100 < calendarPosition.bottom &&
!popoverOnDown)) {
div.classList.add("bottom-full");
div.classList.add("mb-2.5");
div.classList.remove("mt-2.5");
Expand All @@ -244,7 +254,6 @@ const Input: React.FC<Props> = (e: Props) => {
arrow.classList.remove("border-l");
arrow.classList.remove("border-t");
}

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