Skip to content
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

Issue with pop up placement #1451

Open
rp-omar opened this issue Mar 25, 2024 · 8 comments
Open

Issue with pop up placement #1451

rp-omar opened this issue Mar 25, 2024 · 8 comments

Comments

@rp-omar
Copy link

rp-omar commented Mar 25, 2024

Version

@toast-ui/[email protected]

Test Environment

Chrome Version 123, MacOs Sonoma 14

Current Behavior

The eventDetailPopup is not positioned correctly when the Calendar component is in a parent that has a width/height different than 100%, here is a reproduction
https://codesandbox.io/p/sandbox/toast-ui-react-calendar-bug-report-f4522l

Expected Behavior

The eventDetailPopup is positioned correctly. V1 is working fine.

@jithutj
Copy link

jithutj commented Mar 26, 2024

I am also facing the same issue when I put the height: 500px to fix "month" view overlap..
But now the event popup is misplaced.
image

below is the css i added to fix the month view:-

.toastui-calendar-layout.toastui-calendar-month {
                height: 500px !important;
                min-height: 500px;
                max-height: 600px;
            }

@hongrunhui
Copy link

I am also happend, the card will render in error position

@hongrunhui
Copy link

image

@mtangoo
Copy link

mtangoo commented Dec 13, 2024

Have anyone figured out the solution for this?

@1engels
Copy link

1engels commented Dec 29, 2024

Hello guys, I've been testing with this workaround:

Use this in /src/components/popup/eventDetailPopup.tsx

function calculatePopupPosition(eventRect, layoutRect, popupRect) {
  let top = eventRect.top + eventRect.height / 2 - popupRect.height / 2 - layoutRect.top;
  let left = eventRect.left + eventRect.width - layoutRect.left;

  if((eventRect.top + (eventRect.height/2) + (popupRect.height/2)) >= (layoutRect.top + layoutRect.height)){
    top = layoutRect.height - popupRect.height;
  }

  if( top < 0 ) top = eventRect.height;

  const freeSpaceToTheLeft = eventRect.left - layoutRect.left;
  const freeSpaceToTheRight = layoutRect.width - eventRect.width - freeSpaceToTheLeft;

  if(freeSpaceToTheRight < freeSpaceToTheLeft){
    left = eventRect.left - popupRect.width - layoutRect.left;
  }

  if(freeSpaceToTheRight <= popupRect.width && freeSpaceToTheLeft <= popupRect.width){
    left = layoutRect.width / 2 - popupRect.width / 2;
  }

  return [ top, left];
}
function calculatePopupArrowPosition(eventRect, layoutRect, popupRect) {
  const top = eventRect.top + eventRect.height / 2 - layoutRect.top; 
  const popupLeft = eventRect.left + eventRect.width;
  const isOutOfLayout = popupLeft + popupRect.width > layoutRect.left + layoutRect.width;
  var direction = DetailPopupArrowDirection.left;
  if(layoutRect.right == eventRect.right)
    direction = DetailPopupArrowDirection.right;

  return {
    top,
    direction
  };
}

Use this in /src/components/popup/eventFormPopup.tsx

function calculatePopupPosition(popupArrowPointPosition, layoutRect, popupRect) {
  var top = popupArrowPointPosition.top - popupRect.height - HALF_OF_POPUP_ARROW_HEIGHT - layoutRect.top;
  var left = popupArrowPointPosition.left - popupRect.width / 2 - layoutRect.left;
  var direction = FormPopupArrowDirection.bottom
  if(top < 0){
    top = top + popupRect.height + HALF_OF_POPUP_ARROW_HEIGHT;
    direction = FormPopupArrowDirection.top;
  }
  if(left + popupRect.width > layoutRect.width){
    left = layoutRect.width - popupRect.width;
  }
  if(left < 0)
    left = 0;  
  
  return {
    top: top,
    left: left,
    direction : direction
  }
}

And in the line:
const arrowLeftPosition = popupArrowPointPosition.left - left;
Change it to:
const arrowLeftPosition = popupArrowPointPosition.left - left - layoutRect.left;

Edited on Jan 1st:
After a thorough review and testing it in a live website, I realized that the declarative DIV should use the CSS property position: relative, because popups use position: absolute and they will align relative to the first tag that has that property. In my case, I'm using the following code inside a container in Bulma, and I’m not having any issues: <div id="calendar" style="position: relative; height: 1200px"></div>

@mtangoo
Copy link

mtangoo commented Dec 29, 2024

Is this supposed to fix the vanilla JS version too?

@1engels
Copy link

1engels commented Dec 29, 2024

@mtangoo yes, just find the functions and replace the lines that I commented above.

@mtangoo
Copy link

mtangoo commented Dec 29, 2024

Thanks. I'll test early January and post results

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

5 participants