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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT 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

17.24
/projects/igniteui-angular/src/lib/services/overlay/scroll/close-scroll-strategy.ts
1
import { IgxOverlayService } from '../overlay';
2
import { OverlayInfo } from '../utilities';
3
import { ScrollStrategy } from './scroll-strategy';
4

5
/**
6
 * Uses a tolerance and closes the shown component upon scrolling if the tolerance is exceeded
7
 */
8
export class CloseScrollStrategy extends ScrollStrategy {
9
    private _document: Document;
10
    private _overlayService: IgxOverlayService;
11
    private _id: string;
12
    private initialScrollTop: number;
13
    private initialScrollLeft: number;
14
    private _threshold: number;
15
    private _initialized = false;
40✔
16
    private _sourceElement: Element;
17
    private _scrollContainer: HTMLElement;
18
    private _overlayInfo: OverlayInfo;
19

20
    constructor(scrollContainer?: HTMLElement) {
21
        super();
40✔
22
        this._scrollContainer = scrollContainer;
40✔
23
        this._threshold = 10;
40✔
24
    }
25

26
    /**
27
     * Initializes the strategy. Should be called once
28
     *
29
     * @param document reference to Document object.
30
     * @param overlayService IgxOverlay service to use in this strategy.
31
     * @param id Unique id for this strategy.
32
     * ```typescript
33
     * settings.scrollStrategy.initialize(document, overlay, id);
34
     * ```
35
     */
36
    public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
UNCOV
37
        if (this._initialized) {
×
38
            return;
×
39
        }
UNCOV
40
        this._overlayService = overlayService;
×
UNCOV
41
        this._id = id;
×
UNCOV
42
        this._document = document;
×
UNCOV
43
        this._initialized = true;
×
UNCOV
44
        this._overlayInfo = overlayService.getOverlayById(id);
×
45
    }
46

47
    /**
48
     * Attaches the strategy
49
     * ```typescript
50
     * settings.scrollStrategy.attach();
51
     * ```
52
     */
53
    public attach(): void {
UNCOV
54
        if (this._scrollContainer) {
×
55
            this._scrollContainer.addEventListener('scroll', this.onScroll);
×
56
            this._sourceElement = this._scrollContainer;
×
57
        } else {
UNCOV
58
            this._document.addEventListener('scroll', this.onScroll, true);
×
59
        }
60
    }
61

62
    /**
63
     * Detaches the strategy
64
     * ```typescript
65
     * settings.scrollStrategy.detach();
66
     * ```
67
     */
68
    public detach(): void {
69
        // TODO: check why event listener removes only on first call and remains on each next!!!
UNCOV
70
        if (this._scrollContainer) {
×
71
            this._scrollContainer.removeEventListener('scroll', this.onScroll);
×
72
        } else {
UNCOV
73
            this._document.removeEventListener('scroll', this.onScroll, true);
×
74
        }
UNCOV
75
        this._sourceElement = null;
×
UNCOV
76
        this._initialized = false;
×
77
    }
78

79
    private onScroll = (ev: Event) => {
40✔
UNCOV
80
        if (!this._sourceElement) {
×
UNCOV
81
            this._sourceElement = ev.target as any;
×
UNCOV
82
            this.initialScrollTop = this._sourceElement.scrollTop;
×
UNCOV
83
            this.initialScrollLeft = this._sourceElement.scrollLeft;
×
84
        }
85

UNCOV
86
        if (this._overlayInfo.elementRef.nativeElement.contains(this._sourceElement)) {
×
UNCOV
87
            return;
×
88
        }
UNCOV
89
        if (Math.abs(this._sourceElement.scrollTop - this.initialScrollTop) > this._threshold ||
×
90
            Math.abs(this._sourceElement.scrollLeft - this.initialScrollLeft) > this._threshold) {
UNCOV
91
            this._overlayService.hide(this._id);
×
92
        }
93
    };
94
}
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