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

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

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

9.76
/src/dropdown/dropdown-submenu.component.ts
1
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2
import { getElementOffset } from 'ngx-tethys/util';
3

4
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, OnInit, inject, input } from '@angular/core';
5

6
import { ThyDropdownMenuItemDirective } from './dropdown-menu-item.directive';
7

1✔
8
export type ThyDropdownSubmenuDirection = 'left' | 'right' | 'auto';
9

10
type InnerDropdownSubmenuDirection = ThyDropdownSubmenuDirection | 'leftBottom' | 'rightBottom';
11

12
const SUBMENU_CLASS_PREFIX = 'dropdown-submenu';
13

1✔
14
/**
UNCOV
15
 * 下拉子菜单
×
UNCOV
16
 * @name thy-dropdown-submenu,[thyDropdownSubmenu]
×
UNCOV
17
 * @order 40
×
UNCOV
18
 */
×
19
@Component({
UNCOV
20
    selector: '[thyDropdownSubmenu],thy-dropdown-submenu',
×
21
    template: '<ng-content></ng-content>',
22
    host: {
23
        class: 'dropdown-submenu'
24
    },
UNCOV
25
    changeDetection: ChangeDetectionStrategy.OnPush
×
UNCOV
26
})
×
UNCOV
27
export class ThyDropdownSubmenu implements OnInit {
×
28
    private dropdownMenuItem = inject(ThyDropdownMenuItemDirective);
29
    private elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
30

UNCOV
31
    private readonly destroyRef = inject(DestroyRef);
×
UNCOV
32

×
UNCOV
33
    /**
×
UNCOV
34
     * 菜单方向
×
UNCOV
35
     * @type left | right | auto
×
36
     */
37
    readonly thyDirection = input<ThyDropdownSubmenuDirection, ThyDropdownSubmenuDirection>('right', {
UNCOV
38
        transform: (value: ThyDropdownSubmenuDirection) => {
×
39
            return value || 'right';
UNCOV
40
        }
×
41
    });
UNCOV
42

×
43
    ngOnInit(): void {
44
        let direction = this.thyDirection();
45
        this.updateClassByDirection(direction);
UNCOV
46
        this.dropdownMenuItem
×
47
            .bindMouseenterEvent()
48
            .pipe(takeUntilDestroyed(this.destroyRef))
UNCOV
49
            .subscribe(() => {
×
UNCOV
50
                if (this.thyDirection() === 'auto') {
×
UNCOV
51
                    const element = this.dropdownMenuItem.getElement();
×
UNCOV
52
                    const offset = getElementOffset(element);
×
UNCOV
53
                    if (document.documentElement.clientWidth < offset.left + offset.width + offset.width) {
×
54
                        direction = 'left';
UNCOV
55
                    } else {
×
UNCOV
56
                        direction = 'right';
×
57
                    }
58
                    this.updateClassByDirection(direction);
UNCOV
59
                }
×
60
                this.updateVerticalDirection(direction);
61
            });
62
    }
63

1✔
64
    private updateClassByDirection(direction: InnerDropdownSubmenuDirection) {
65
        this.dropdownMenuItem.updateClass([`${SUBMENU_CLASS_PREFIX}-${direction}`]);
66
    }
67

1✔
68
    private updateVerticalDirection(direction: InnerDropdownSubmenuDirection) {
69
        const submenuItems = this.elementRef.nativeElement.querySelectorAll('.dropdown-menu-item');
70
        if (submenuItems.length) {
71
            let submenuItemHeight = 0;
72
            submenuItems.forEach(item => (submenuItemHeight += item.clientHeight));
73
            if (
74
                document.documentElement.clientHeight - this.dropdownMenuItem.getElement().getBoundingClientRect().bottom <
75
                submenuItemHeight
76
            ) {
77
                direction = direction === 'left' ? 'leftBottom' : 'rightBottom';
78
                this.updateClassByDirection(direction);
79
            } else {
80
                this.updateClassByDirection(direction);
81
            }
82
        }
83
    }
84
}
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