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

IgniteUI / igniteui-webcomponents / 28880951667

07 Jul 2026 04:10PM UTC coverage: 98.335% (+0.008%) from 98.327%
28880951667

Pull #2278

github

web-flow
Merge ca7adce28 into fcab913eb
Pull Request #2278: chore: more analyzer ignore tags

5941 of 6247 branches covered (95.1%)

Branch coverage included in aggregate %.

24 of 24 new or added lines in 15 files covered. (100.0%)

16 existing lines in 4 files now uncovered.

42028 of 42534 relevant lines covered (98.81%)

1581.86 hits per line

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

98.05
/src/components/tree/tree.ts
1
import {
9✔
2
  type ITreeResourceStrings,
9✔
3
  TreeResourceStringsEN,
9✔
4
} from 'igniteui-i18n-core';
9✔
5
import { html, LitElement, type PropertyValues } from 'lit';
9✔
6
import { property } from 'lit/decorators.js';
9✔
7
import { addThemingController } from '../../theming/theming-controller.js';
9✔
8
import { blazorAdditionalDependencies } from '../common/decorators/blazorAdditionalDependencies.js';
9✔
9
import { registerComponent } from '../common/definitions/register.js';
9✔
10
import { addI18nController } from '../common/i18n/i18n-controller.js';
9✔
11
import type { Constructor } from '../common/mixins/constructor.js';
9✔
12
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
9✔
13
import type { TreeSelection } from '../types.js';
9✔
14
import { styles } from './themes/container.base.css.js';
9✔
15
import { all } from './themes/container.js';
9✔
16
import type { IgcTreeComponentEventMap } from './tree.common.js';
9✔
17
import { IgcTreeNavigationService } from './tree.navigation.js';
9✔
18
import { IgcTreeSelectionService } from './tree.selection.js';
9✔
19
import IgcTreeItemComponent from './tree-item.js';
9✔
20

9✔
21
/**
9✔
22
 * The tree allows users to represent hierarchical data in a tree-view structure,
9✔
23
 * maintaining parent-child relationships, as well as to define static tree-view structure without a corresponding data model.
9✔
24
 *
9✔
25
 * @element igc-tree
9✔
26
 *
9✔
27
 * @slot - Renders the tree items inside default slot.
9✔
28
 *
9✔
29
 * @fires igcSelection - Emitted when item selection is changing, before the selection completes.
9✔
30
 * @fires igcItemCollapsed - Emitted when tree item is collapsed.
9✔
31
 * @fires igcItemCollapsing - Emitted when tree item is about to collapse.
9✔
32
 * @fires igcItemExpanded - Emitted when tree item is expanded.
9✔
33
 * @fires igcItemExpanding - Emitted when tree item is about to expand.
9✔
34
 * @fires igcActiveItem - Emitted when the tree's `active` item changes.
9✔
35
 */
9✔
36
@blazorAdditionalDependencies('IgcTreeItemComponent')
9✔
37
export default class IgcTreeComponent extends EventEmitterMixin<
9✔
38
  IgcTreeComponentEventMap,
9✔
39
  Constructor<LitElement>
9✔
40
>(LitElement) {
9✔
41
  public static readonly tagName = 'igc-tree';
9✔
42
  public static styles = styles;
9✔
43

9✔
44
  /* blazorSuppress */
9✔
45
  public static register() {
9✔
46
    registerComponent(IgcTreeComponent, IgcTreeItemComponent);
9✔
47
  }
9✔
48

9✔
49
  private readonly _i18nController = addI18nController<ITreeResourceStrings>(
9✔
50
    this,
9✔
51
    {
9✔
52
      defaultEN: TreeResourceStringsEN,
9✔
53
    }
9✔
54
  );
9✔
55

9✔
56
  /** @hidden @internal */
9✔
57
  public selectionService!: IgcTreeSelectionService;
9✔
58

9✔
59
  /** @hidden @internal */
9✔
60
  public navService!: IgcTreeNavigationService;
9✔
61

9✔
62
  /**
9✔
63
   * Whether a single or multiple of a parent's child items can be expanded.
9✔
64
   * @attr single-branch-expand
9✔
65
   */
9✔
66
  @property({ attribute: 'single-branch-expand', reflect: true, type: Boolean })
9✔
67
  public singleBranchExpand = false;
9✔
68

9✔
69
  /**
9✔
70
   * Whether clicking over nodes will change their expanded state or not.
9✔
71
   * @attr toggle-node-on-click
9✔
72
   */
9✔
73
  @property({ attribute: 'toggle-node-on-click', reflect: true, type: Boolean })
9✔
74
  public toggleNodeOnClick = false;
9✔
75

9✔
76
  /**
9✔
77
   * The selection state of the tree.
9✔
78
   * @attr
9✔
79
   */
9✔
80
  @property({ reflect: true })
9✔
81
  public selection: TreeSelection = 'none';
9✔
82

9✔
83
  /**
9✔
84
   * Gets/Sets the locale used for getting language, affecting resource strings.
9✔
85
   * @attr locale
9✔
86
   */
9✔
87
  @property()
9✔
88
  public set locale(value: string) {
9✔
UNCOV
89
    this._i18nController.locale = value;
×
UNCOV
90
  }
×
91

9✔
92
  public get locale() {
9✔
93
    return this._i18nController.locale;
114✔
94
  }
114✔
95

9✔
96
  /**
9✔
97
   * The resource strings for localization.
9✔
98
   * Currently only aria-labels of the default expand/collapse icons are localized for the tree item.
9✔
99
   */
9✔
100
  @property({ attribute: false })
9✔
101
  public set resourceStrings(value: ITreeResourceStrings) {
9✔
UNCOV
102
    this._i18nController.resourceStrings = value;
×
UNCOV
103
  }
×
104

9✔
105
  public get resourceStrings(): ITreeResourceStrings {
9✔
106
    return this._i18nController.resourceStrings;
971✔
107
  }
971✔
108

9✔
109
  /* blazorSuppress */
9✔
110
  /**
9✔
111
   * Returns all of the tree's items.
9✔
112
   */
9✔
113
  public get items(): IgcTreeItemComponent[] {
9✔
114
    const result: IgcTreeItemComponent[] = [];
582✔
115
    for (const el of this.children) {
582✔
116
      if (el.tagName.toLowerCase() === IgcTreeItemComponent.tagName) {
1,716✔
117
        const item = el as IgcTreeItemComponent;
1,716✔
118
        result.push(item, ...item.getChildren({ flatten: true }));
1,716✔
119
      }
1,716✔
120
    }
1,716✔
121
    return result;
582✔
122
  }
582✔
123

9✔
124
  constructor() {
9✔
125
    super();
114✔
126

114✔
127
    addThemingController(this, all);
114✔
128

114✔
129
    this.selectionService = new IgcTreeSelectionService(this);
114✔
130
    this.navService = new IgcTreeNavigationService(this, this.selectionService);
114✔
131
  }
114✔
132

9✔
133
  public override connectedCallback(): void {
9✔
134
    super.connectedCallback();
114✔
135
    this.setAttribute('role', 'tree');
114✔
136
    const items = this.items;
114✔
137
    // set init to true for all items which are rendered along with the tree
114✔
138
    for (const item of items) {
114✔
139
      item.init = true;
1,362✔
140
    }
1,362✔
141
    const firstNotDisabledItem = items.find((i) => !i.disabled);
114✔
142
    if (firstNotDisabledItem) {
114✔
143
      firstNotDisabledItem.tabIndex = 0;
94✔
144
      this.navService.focusItem(firstNotDisabledItem);
94✔
145
    }
94✔
146
  }
114✔
147

9✔
148
  protected override willUpdate(changed: PropertyValues<this>): void {
9✔
149
    super.willUpdate(changed);
129✔
150

129✔
151
    if (this.hasUpdated && changed.has('selection')) {
129✔
152
      this._selectionModeChange();
9✔
153
    }
9✔
154

129✔
155
    if (changed.has('singleBranchExpand')) {
129✔
156
      this._singleBranchExpandChange();
118✔
157
    }
118✔
158

129✔
159
    if (changed.has('selection') || changed.has('resourceStrings')) {
129✔
160
      for (const item of this.items) {
123✔
161
        item.requestUpdate();
1,458✔
162
      }
1,458✔
163
    }
123✔
164
  }
129✔
165

9✔
166
  private _selectionModeChange(): void {
9✔
167
    this.selectionService.clearItemsSelection();
9✔
168
  }
9✔
169

9✔
170
  private _singleBranchExpandChange(): void {
9✔
171
    if (this.singleBranchExpand) {
118✔
172
      // if activeItem -> do not collapse its branch
4✔
173
      if (this.navService.activeItem) {
4✔
174
        const path = this.navService.activeItem.path;
1✔
175
        const remainExpanded = new Set(path.splice(0, path.length - 1));
1✔
176
        this.items.forEach((item) => {
1✔
177
          if (!remainExpanded.has(item)) {
14✔
178
            item.collapseWithEvent();
12✔
179
          }
12✔
180
        });
1✔
181
      } else {
4✔
182
        for (const item of this.items) {
3✔
183
          item.collapseWithEvent();
42✔
184
        }
42✔
185
      }
3✔
186
    }
4✔
187
  }
118✔
188

9✔
189
  /* blazorSuppress */
9✔
190
  /** @hidden @internal */
9✔
191
  public expandToItem(item: IgcTreeItemComponent): void {
9✔
192
    if (item?.parent) {
45✔
193
      item.path.forEach((i) => {
29✔
194
        if (i !== item && !i.expanded) {
61✔
195
          i.expanded = true;
3✔
196
        }
3✔
197
      });
29✔
198
    }
29✔
199
  }
45✔
200

9✔
201
  /* blazorSuppress */
9✔
202
  /** Select all items if the items collection is empty. Otherwise, select the items in the items collection. */
9✔
203
  public select(
9✔
204
    /* alternateType: TreeItemCollection */
7✔
205
    items?: IgcTreeItemComponent[]
7✔
206
  ): void {
7✔
207
    if (!items) {
7✔
208
      this.selectionService.selectItemsWithNoEvent(
1✔
209
        this.selection === 'cascade'
1!
UNCOV
210
          ? this.items.filter((item) => item.level === 0)
×
211
          : this.items
1✔
212
      );
1✔
213
    } else {
7✔
214
      this.selectionService.selectItemsWithNoEvent(items);
6✔
215
    }
6✔
216
  }
7✔
217

9✔
218
  /* blazorSuppress */
9✔
219
  /** Deselect all items if the items collection is empty. Otherwise, deselect the items in the items collection. */
9✔
220
  public deselect(
9✔
221
    /* alternateType: TreeItemCollection */
7✔
222
    items?: IgcTreeItemComponent[]
7✔
223
  ): void {
7✔
224
    this.selectionService.deselectItemsWithNoEvent(items);
7✔
225
  }
7✔
226

9✔
227
  /* blazorSuppress */
9✔
228
  /**
9✔
229
   * Expands all of the passed items.
9✔
230
   * If no items are passed, expands ALL items.
9✔
231
   */
9✔
232
  public expand(
9✔
233
    /* alternateType: TreeItemCollection */
9✔
234
    items?: IgcTreeItemComponent[]
9✔
235
  ): void {
9✔
236
    const _items = items || this.items;
9✔
237
    _items.forEach((item) => {
9✔
238
      item.expanded = true;
67✔
239
    });
9✔
240
  }
9✔
241

9✔
242
  /* blazorSuppress */
9✔
243
  /**
9✔
244
   * Collapses all of the passed items.
9✔
245
   * If no items are passed, collapses ALL items.
9✔
246
   */
9✔
247
  public collapse(
9✔
248
    /* alternateType: TreeItemCollection */
2✔
249
    items?: IgcTreeItemComponent[]
2✔
250
  ): void {
2✔
251
    const _items = items || this.items;
2✔
252
    _items.forEach((item) => {
2✔
253
      item.expanded = false;
9✔
254
    });
2✔
255
  }
2✔
256

9✔
257
  protected override render() {
9✔
258
    return html`<slot></slot>`;
129✔
259
  }
129✔
260
}
9✔
261

9✔
262
declare global {
9✔
263
  interface HTMLElementTagNameMap {
9✔
264
    'igc-tree': IgcTreeComponent;
9✔
265
  }
9✔
266
}
9✔
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

© 2026 Coveralls, Inc