Window with initialheight and initialWidth is not centered in the viewport

1 Answer 24 Views
Window
Mat
Top achievements
Rank 1
Iron
Iron
Iron
Mat asked on 15 Nov 2024, 09:33 AM

I'm setting both the initialWidth and initialHewight (600 and 400) to the Windows is large enough for the content, but it's not initially positioned at the center of the viewport when opened.

It displayed at the correct size, but it's too far to the right and too close to the bottom.

Any ideas why?

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 20 Nov 2024, 09:06 AM

Hello,

In KendoReact, the position of a Window component depends on how its position properties (e.g., left, top) are calculated. If you're experiencing an issue where the window is not centered, it's likely due to how the initial position is being set (or not set). You can ensure that the initialTop and initialLeft are properly calculated to center the window in the viewport by calculating the center position dynamically:

  const viewportWidth = window.innerWidth;
  const viewportHeight = window.innerHeight;

  const windowWidth = 600; // Match your `initialWidth`
  const windowHeight = 400; // Match your `initialHeight`

  const centeredTop = (viewportHeight - windowHeight) / 2;
  const centeredLeft = (viewportWidth - windowWidth) / 2;

Please, give this solution a try and let me know if the problem persists.

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Window
Asked by
Mat
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Vessy
Telerik team
Share this question
or