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

Window updatePosition setWindowTop sets wrong positions #911

Closed
howudodat opened this issue Feb 8, 2024 · 0 comments
Closed

Window updatePosition setWindowTop sets wrong positions #911

howudodat opened this issue Feb 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request version 2.x.x Version 2.x.x issues
Milestone

Comments

@howudodat
Copy link

Describe the bug
Window#updatePostion() line 207 is setting modalElement.element().style.left but should be setting modalElement.element().style.top

additionally the block of code at line 220-227 breaks the block at 203-218 and can be completely removed

      if (windowTop < 0) {
        modalElement.element().style.top =
            (fixed ? 0 : DomGlobal.window.pageYOffset)
                - ((initialHeight - windowHeight) / 2)
                + "px";
      } else {
        modalElement.element().style.top = windowTop + "px";
      }

To Reproduce
create Window
call setWindowTop(), then setFixed()

Expected behavior
set modalElement.element().style.top

Prposed new updatePostion() function:

  private void updatePosition() {
    if (maximized) {
      modalElement.element().style.left = "0px";
      modalElement.element().style.top = "0px";
    } else {
      DOMRect windowRect = modalElement.element().getBoundingClientRect();
      double initialWidth = windowRect.width;
      double windowWidth = DomGlobal.window.innerWidth;
      double initialHeight = windowRect.height;
      double windowHeight = DomGlobal.window.innerHeight;

      if (windowLeft > 0) {
        if (windowLeft < (windowWidth - initialWidth)) {
          modalElement.element().style.left = windowLeft + "px";
        } else {
          modalElement.element().style.left =
              windowLeft
                  - ((windowLeft + initialWidth) - windowWidth - DomGlobal.window.pageXOffset)
                  - elements.body().element().getBoundingClientRect().left
                  + "px";
        }
      } else {
        modalElement.element().style.left =
            ((windowWidth - initialWidth) / 2)
                + ((fixed ? 0 : DomGlobal.window.pageXOffset))
                - elements.body().element().getBoundingClientRect().left
                + "px";
      }

      if (windowTop > 0) {
        if (windowTop < (windowHeight - initialHeight)) {
          modalElement.element().style.top = windowTop + "px";
        } else {
          modalElement.element().style.top =
              windowTop
                  - ((windowLeft + initialHeight) - windowHeight - DomGlobal.window.pageYOffset)
                  + "px";
        }
      } else {
        modalElement.element().style.top =
            (fixed ? 0 : DomGlobal.window.pageYOffset)
                - ((initialHeight - windowHeight) / 2)
                + "px";
        ;
      }
    }
  }
@vegegoku vegegoku self-assigned this Mar 18, 2024
@vegegoku vegegoku added enhancement New feature or request version 2.x.x Version 2.x.x issues labels Mar 18, 2024
@vegegoku vegegoku added this to the 2.0.1 milestone Mar 18, 2024
@vegegoku vegegoku changed the title V2 Window updatePosition setWindowTop sets wrong positions Window updatePosition setWindowTop sets wrong positions Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request version 2.x.x Version 2.x.x issues
Projects
None yet
Development

No branches or pull requests

2 participants