• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM UTC coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/projects/igniteui-angular/src/lib/services/overlay/position/connected-positioning-strategy.ts
1
import { scaleInVerTop, scaleOutVerTop } from 'igniteui-angular/animations';
2
import { ConnectedFit } from '../utilities';
3
import {
4
  HorizontalAlignment,
5
  Point,
6
  PositionSettings,
7
  Size,
8
  Util,
9
  VerticalAlignment
10
} from './../utilities';
11
import { IPositionStrategy } from './IPositionStrategy';
12

13
/**
14
 * Positions the element based on the directions and start point passed in trough PositionSettings.
15
 * It is possible to either pass a start point or an HTMLElement as a positioning base.
16
 */
17
export class ConnectedPositioningStrategy implements IPositionStrategy {
18
  /**
19
   * PositionSettings to use when position the component in the overlay
20
   */
21
  public settings: PositionSettings;
22

23
  private _defaultSettings: PositionSettings = {
1,068✔
24
    horizontalDirection: HorizontalAlignment.Right,
25
    verticalDirection: VerticalAlignment.Bottom,
26
    horizontalStartPoint: HorizontalAlignment.Left,
27
    verticalStartPoint: VerticalAlignment.Bottom,
28
    openAnimation: scaleInVerTop,
29
    closeAnimation: scaleOutVerTop,
30
    minSize: { width: 0, height: 0 }
31
  };
32

33
  constructor(settings?: PositionSettings) {
34
    this.settings = Object.assign({}, this._defaultSettings, settings);
1,068✔
35
  }
36

37
  /**
38
   * Position the element based on the PositionStrategy implementing this interface.
39
   *
40
   * @param contentElement The HTML element to be positioned
41
   * @param size Size of the element
42
   * @param document reference to the Document object
43
   * @param initialCall should be true if this is the initial call to the method
44
   * @param target attaching target for the component to show
45
   * ```typescript
46
   * settings.positionStrategy.position(content, size, document, true);
47
   * ```
48
   */
49
  public position(contentElement: HTMLElement, size: Size, document?: Document, initialCall?: boolean, target?: Point | HTMLElement): void {
50
    const rects = this.calculateElementRectangles(contentElement, target);
39✔
51
    this.setStyle(contentElement, rects.targetRect, rects.elementRect, {});
39✔
52
  }
53

54
  /**
55
   * Creates clone of this position strategy
56
   * @returns clone of this position strategy
57
   */
58
  public clone(): IPositionStrategy {
UNCOV
59
    return Util.cloneInstance(this);
×
60
  }
61

62
  /**
63
   * Obtains the DomRect objects for the required elements - target and element to position
64
   *
65
   * @returns target and element DomRect objects
66
   */
67
   protected calculateElementRectangles(contentElement, target: Point | HTMLElement):
68
   { targetRect: Partial<DOMRect>; elementRect: Partial<DOMRect> } {
69
    return {
78✔
70
      targetRect: Util.getTargetRect(target),
71
      elementRect: contentElement.getBoundingClientRect() as DOMRect
72
    };
73
  }
74

75
  /**
76
   * Sets element's style which effectively positions provided element according
77
   * to provided position settings
78
   *
79
   * @param element Element to position
80
   * @param targetRect Bounding rectangle of strategy target
81
   * @param elementRect Bounding rectangle of the element
82
   */
83
  protected setStyle(element: HTMLElement, targetRect: Partial<DOMRect>, elementRect: Partial<DOMRect>, connectedFit: ConnectedFit) {
84
    const horizontalOffset = connectedFit.horizontalOffset ? connectedFit.horizontalOffset : 0;
78!
85
    const verticalOffset = connectedFit.verticalOffset ? connectedFit.verticalOffset : 0;
78!
86
    const startPoint: Point = {
78✔
87
      x: targetRect.right + targetRect.width * this.settings.horizontalStartPoint + horizontalOffset,
88
      y: targetRect.bottom + targetRect.height * this.settings.verticalStartPoint + verticalOffset
89
    };
90
    const wrapperRect: ClientRect = element.parentElement.getBoundingClientRect();
78✔
91

92
    //  clean up styles - if auto position strategy is chosen we may pass here several times
93
    element.style.right = '';
78✔
94
    element.style.left = '';
78✔
95
    element.style.bottom = '';
78✔
96
    element.style.top = '';
78✔
97

98
    switch (this.settings.horizontalDirection) {
78!
99
      case HorizontalAlignment.Left:
UNCOV
100
        element.style.right = `${Math.round(wrapperRect.right - startPoint.x)}px`;
×
UNCOV
101
        break;
×
102
      case HorizontalAlignment.Center:
103
        element.style.left = `${Math.round(startPoint.x - wrapperRect.left - elementRect.width / 2)}px`;
37✔
104
        break;
37✔
105
      case HorizontalAlignment.Right:
106
        element.style.left = `${Math.round(startPoint.x - wrapperRect.left)}px`;
41✔
107
        break;
41✔
108
    }
109

110
    switch (this.settings.verticalDirection) {
78✔
111
      case VerticalAlignment.Top:
112
        element.style.bottom = `${Math.round(wrapperRect.bottom - startPoint.y)}px`;
6✔
113
        break;
6✔
114
      case VerticalAlignment.Middle:
115
        element.style.top = `${Math.round(startPoint.y - wrapperRect.top - elementRect.height / 2)}px`;
37✔
116
        break;
37✔
117
      case VerticalAlignment.Bottom:
118
        element.style.top = `${Math.round(startPoint.y - wrapperRect.top)}px`;
35✔
119
        break;
35✔
120
    }
121
  }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc