Skip to content

Commit

Permalink
PR (#1)
Browse files Browse the repository at this point in the history
Fixes dom handler moving elements off screen when size is too small and screen has set size.
  • Loading branch information
JacobSiegle authored Nov 17, 2018
1 parent 5ff3683 commit 2db7386
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/app/components/dom/domhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ export class DomHandler {
public relativePosition(element: any, target: any): void {
let elementDimensions = element.offsetParent ? { width: element.offsetWidth, height: element.offsetHeight } : this.getHiddenElementDimensions(element);
let targetHeight = target.offsetHeight;
let targetWidth = target.offsetWidth;
let targetOffset = target.getBoundingClientRect();
let windowScrollTop = this.getWindowScrollTop();
let viewport = this.getViewport();
let top, left;

if ((targetOffset.top + targetHeight + elementDimensions.height) > viewport.height) {
top = -1 * (elementDimensions.height);
if(targetOffset.top + top < 0) {
Expand All @@ -98,12 +96,13 @@ export class DomHandler {
else {
top = targetHeight;
}
if ((targetOffset.left + elementDimensions.width) > viewport.width)
left = targetWidth - elementDimensions.width;
else

if ((targetOffset.left + elementDimensions.width) > viewport.width) {
left = (targetOffset.left * -1) / 2;
}
else {
left = 0;
}

element.style.top = top + 'px';
element.style.left = left + 'px';
Expand Down

0 comments on commit 2db7386

Please sign in to comment.