New to Kendo UI for Angular? Start a free 30-day trial

Restricting the Window to the Viewport

Environment

ProductProgress® Kendo UI for Angular Window

Description

The Kendo UI for Angular Window component can be dragged anywhere on the screen by the end user. How to restrict the end user from dragging it beyond a container viewport?

Solution

To ensure that the Window component cannot leave a specified wrapper or viewport, update its top, left, and height properties in accordance with the current size and position of the component while dragging.

  1. Handle the leftChange and topChange events of the Window.

    <kendo-window
            (leftChange)="restrictMovement()"
            (topChange)="restrictMovement()"
            ...
          >
    	...
    </kendo-window>
  2. Use the getBoundingClientRect DOM element method to get information about the position of the Window wrapper element relative to the viewport.

      ngAfterViewInit(): void {
        this.wrapper = this.winWrapper.nativeElement.getBoundingClientRect();
      }
  3. Implement conditions that check whether the Window leaves the boundaries of its wrapper and update the top and left properties accordingly. When the component is minimized, update the height property to consider the new dimensions of the Window while dragging.

The following example demonstrates the full implementation of the suggested approach.

Example
View Source
Change Theme:

In this article

Not finding the help you need?