@fluentui/web-components 3.0.0-beta.85 → 3.0.0-beta.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -2
- package/dist/dts/tree/index.d.ts +1 -0
- package/dist/dts/tree/tree.base.d.ts +68 -0
- package/dist/dts/tree/tree.d.ts +7 -67
- package/dist/dts/tree-item/index.d.ts +1 -0
- package/dist/dts/tree-item/tree-item.base.d.ts +99 -0
- package/dist/dts/tree-item/tree-item.d.ts +5 -88
- package/dist/dts/tree-item/tree-item.options.d.ts +2 -2
- package/dist/esm/tree/index.js +1 -0
- package/dist/esm/tree/index.js.map +1 -1
- package/dist/esm/tree/tree.base.js +232 -0
- package/dist/esm/tree/tree.base.js.map +1 -0
- package/dist/esm/tree/tree.js +10 -229
- package/dist/esm/tree/tree.js.map +1 -1
- package/dist/esm/tree/tree.template.js +3 -2
- package/dist/esm/tree/tree.template.js.map +1 -1
- package/dist/esm/tree-item/index.js +1 -0
- package/dist/esm/tree-item/index.js.map +1 -1
- package/dist/esm/tree-item/tree-item.base.js +165 -0
- package/dist/esm/tree-item/tree-item.base.js.map +1 -0
- package/dist/esm/tree-item/tree-item.js +13 -149
- package/dist/esm/tree-item/tree-item.js.map +1 -1
- package/dist/esm/tree-item/tree-item.styles.js +8 -21
- package/dist/esm/tree-item/tree-item.styles.js.map +1 -1
- package/dist/esm/tree-item/tree-item.template.js +5 -7
- package/dist/esm/tree-item/tree-item.template.js.map +1 -1
- package/dist/web-components.d.ts +104 -88
- package/dist/web-components.js +851 -800
- package/dist/web-components.min.js +229 -229
- package/package.json +1 -1
package/dist/esm/tree/tree.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { attr
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export class Tree extends FASTElement {
|
|
2
|
+
import { attr } from '@microsoft/fast-element';
|
|
3
|
+
import { TreeItemAppearance, TreeItemSize } from '../tree-item/tree-item.options';
|
|
4
|
+
import { BaseTree } from './tree.base';
|
|
5
|
+
export class Tree extends BaseTree {
|
|
7
6
|
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
/**
|
|
10
|
-
* The currently selected tree item
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
this.currentSelected = null;
|
|
14
|
-
/**
|
|
15
|
-
* The tree item that is designated to be in the tab queue.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
this.currentFocused = null;
|
|
20
|
-
/**
|
|
21
|
-
* The internal {@link https://developer.mozilla.org/docs/Web/API/ElementInternals | `ElementInternals`} instance for the component.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
this.elementInternals = this.attachInternals();
|
|
7
|
+
super(...arguments);
|
|
26
8
|
/**
|
|
27
9
|
* The size of the tree item element
|
|
28
10
|
* @public
|
|
@@ -35,8 +17,6 @@ export class Tree extends FASTElement {
|
|
|
35
17
|
* HTML Attribute: appearance
|
|
36
18
|
*/
|
|
37
19
|
this.appearance = TreeItemAppearance.subtle;
|
|
38
|
-
this.childTreeItems = [];
|
|
39
|
-
this.elementInternals.role = 'tree';
|
|
40
20
|
}
|
|
41
21
|
sizeChanged() {
|
|
42
22
|
this.updateSizeAndAppearance();
|
|
@@ -44,9 +24,13 @@ export class Tree extends FASTElement {
|
|
|
44
24
|
appearanceChanged() {
|
|
45
25
|
this.updateSizeAndAppearance();
|
|
46
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* child tree items supered change event
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
47
31
|
childTreeItemsChanged() {
|
|
32
|
+
super.childTreeItemsChanged();
|
|
48
33
|
this.updateSizeAndAppearance();
|
|
49
|
-
this.updateCurrentSelected();
|
|
50
34
|
}
|
|
51
35
|
/**
|
|
52
36
|
* 1. Update the child items' size based on the tree's size
|
|
@@ -57,218 +41,15 @@ export class Tree extends FASTElement {
|
|
|
57
41
|
return;
|
|
58
42
|
}
|
|
59
43
|
this.childTreeItems.forEach(item => {
|
|
60
|
-
if (!isTreeItem(item)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
44
|
item.size = this.size;
|
|
64
45
|
item.appearance = this.appearance;
|
|
65
46
|
});
|
|
66
47
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Updates current selected when slottedTreeItems changes
|
|
69
|
-
*/
|
|
70
|
-
updateCurrentSelected() {
|
|
71
|
-
// force single selection
|
|
72
|
-
// defaults to first one found
|
|
73
|
-
const selectedItem = this.querySelector(`[aria-selected='true']`);
|
|
74
|
-
this.currentSelected = selectedItem;
|
|
75
|
-
// invalidate the current focused item if it is no longer valid
|
|
76
|
-
if (this.currentFocused === null || !this.contains(this.currentFocused)) {
|
|
77
|
-
this.currentFocused = this.getValidFocusableItem();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* KeyDown handler
|
|
82
|
-
*
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
keydownHandler(e) {
|
|
86
|
-
if (e.defaultPrevented) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const item = e.target;
|
|
90
|
-
if (!isTreeItem(item) || this.childTreeItems.length < 1) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
const elements = this.getVisibleNodes();
|
|
94
|
-
switch (e.key) {
|
|
95
|
-
case keyHome: {
|
|
96
|
-
if (elements.length) {
|
|
97
|
-
elements[0].focus();
|
|
98
|
-
}
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
case keyEnd: {
|
|
102
|
-
if (elements.length) {
|
|
103
|
-
elements[elements.length - 1].focus();
|
|
104
|
-
}
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
case keyArrowLeft: {
|
|
108
|
-
if (item?.childTreeItems?.length && item.expanded) {
|
|
109
|
-
item.expanded = false;
|
|
110
|
-
}
|
|
111
|
-
else if (isTreeItem(item.parentElement)) {
|
|
112
|
-
item.parentElement.focus();
|
|
113
|
-
}
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
case keyArrowRight: {
|
|
117
|
-
if (item?.childTreeItems?.length) {
|
|
118
|
-
if (!item.expanded) {
|
|
119
|
-
item.expanded = true;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
this.focusNextNode(1, item);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
case keyArrowDown: {
|
|
128
|
-
this.focusNextNode(1, item);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
case keyArrowUp: {
|
|
132
|
-
this.focusNextNode(-1, item);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
case keyEnter: {
|
|
136
|
-
// In single-select trees where selection does not follow focus (see note below),
|
|
137
|
-
// the default action is typically to select the focused node.
|
|
138
|
-
this.clickHandler(e);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
case keySpace: {
|
|
142
|
-
item.toggleSelection();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// don't prevent default if we took no action
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Handle focus events
|
|
151
|
-
*
|
|
152
|
-
* @internal
|
|
153
|
-
*/
|
|
154
|
-
focusHandler(e) {
|
|
155
|
-
if (this.childTreeItems.length < 1) {
|
|
156
|
-
// no child items, nothing to do
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (e.target === this) {
|
|
160
|
-
if (this.currentFocused === null) {
|
|
161
|
-
this.currentFocused = this.getValidFocusableItem();
|
|
162
|
-
}
|
|
163
|
-
if (this.currentFocused !== null) {
|
|
164
|
-
this.currentFocused.focus();
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (this.contains(e.target)) {
|
|
169
|
-
this.setAttribute('tabindex', '-1');
|
|
170
|
-
this.currentFocused = e.target;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Handle blur events
|
|
175
|
-
*
|
|
176
|
-
* @internal
|
|
177
|
-
*/
|
|
178
|
-
blurHandler(e) {
|
|
179
|
-
if (e.target instanceof HTMLElement && (e.relatedTarget === null || !this.contains(e.relatedTarget))) {
|
|
180
|
-
this.setAttribute('tabindex', '0');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Handles click events bubbling up
|
|
185
|
-
*
|
|
186
|
-
* @internal
|
|
187
|
-
*/
|
|
188
|
-
clickHandler(e) {
|
|
189
|
-
if (e.defaultPrevented) {
|
|
190
|
-
// handled, do nothing
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (!isTreeItem(e.target)) {
|
|
194
|
-
// not a tree item, ignore
|
|
195
|
-
// return true, do not prevent default
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
const item = e.target;
|
|
199
|
-
item.toggleExpansion();
|
|
200
|
-
item.toggleSelection();
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Handles the selected-changed events bubbling up
|
|
204
|
-
* from child tree items
|
|
205
|
-
*
|
|
206
|
-
* @internal
|
|
207
|
-
*/
|
|
208
|
-
changeHandler(e) {
|
|
209
|
-
if (e.defaultPrevented) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (!isTreeItem(e.target)) {
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
const item = e.target;
|
|
216
|
-
if (item.selected) {
|
|
217
|
-
// Deselect the prevously selected item
|
|
218
|
-
if (this.currentSelected && this.currentSelected !== item && this.currentSelected instanceof TreeItem) {
|
|
219
|
-
this.currentSelected.selected = false;
|
|
220
|
-
}
|
|
221
|
-
// New selected item
|
|
222
|
-
this.currentSelected = item;
|
|
223
|
-
}
|
|
224
|
-
else if (!item.selected && this.currentSelected === item) {
|
|
225
|
-
// Selected item deselected
|
|
226
|
-
this.currentSelected = null;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* checks if there are any nested tree items
|
|
231
|
-
*/
|
|
232
|
-
getValidFocusableItem() {
|
|
233
|
-
const elements = this.getVisibleNodes();
|
|
234
|
-
// default to selected element if there is one
|
|
235
|
-
let focusIndex = elements.findIndex(el => el.selected);
|
|
236
|
-
if (focusIndex === -1) {
|
|
237
|
-
// otherwise first focusable tree item
|
|
238
|
-
focusIndex = elements.findIndex(el => el instanceof TreeItem);
|
|
239
|
-
}
|
|
240
|
-
if (focusIndex !== -1) {
|
|
241
|
-
return elements[focusIndex];
|
|
242
|
-
}
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
getVisibleNodes() {
|
|
246
|
-
return Array.from(this.querySelectorAll('*')).filter(node => isTreeItem(node) && node.offsetParent !== null);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Move focus to a tree item based on its offset from the provided item
|
|
250
|
-
*/
|
|
251
|
-
focusNextNode(delta, item) {
|
|
252
|
-
const visibleNodes = this.getVisibleNodes();
|
|
253
|
-
if (!visibleNodes.length) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const focusItem = visibleNodes[visibleNodes.indexOf(item) + delta];
|
|
257
|
-
if (isHTMLElement(focusItem)) {
|
|
258
|
-
focusItem.focus();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
48
|
}
|
|
262
|
-
__decorate([
|
|
263
|
-
observable
|
|
264
|
-
], Tree.prototype, "currentSelected", void 0);
|
|
265
49
|
__decorate([
|
|
266
50
|
attr
|
|
267
51
|
], Tree.prototype, "size", void 0);
|
|
268
52
|
__decorate([
|
|
269
53
|
attr
|
|
270
54
|
], Tree.prototype, "appearance", void 0);
|
|
271
|
-
__decorate([
|
|
272
|
-
observable
|
|
273
|
-
], Tree.prototype, "childTreeItems", void 0);
|
|
274
55
|
//# sourceMappingURL=tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/tree/tree.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/tree/tree.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,OAAO,IAAK,SAAQ,QAAQ;IAAlC;;QACE;;;;WAIG;QAEI,SAAI,GAAiB,YAAY,CAAC,KAAK,CAAC;QAK/C;;;;WAIG;QAEI,eAAU,GAAuB,kBAAkB,CAAC,MAAM,CAAC;IA4BpE,CAAC;IAtCS,WAAW;QACjB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IASO,iBAAiB;QACvB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,qBAAqB;QAC1B,KAAK,CAAC,qBAAqB,EAAE,CAAC;QAC9B,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,uBAAuB;QAC5B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAChC,IAAiB,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACnC,IAAiB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvCQ;IADN,IAAI;kCAC0C;AAWxC;IADN,IAAI;wCAC6D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { children,
|
|
1
|
+
import { children, html } from '@microsoft/fast-element';
|
|
2
|
+
import { isTreeItem } from '../tree-item/tree-item.options';
|
|
2
3
|
export const template = html `
|
|
3
4
|
<template
|
|
4
5
|
tabindex="0"
|
|
@@ -9,7 +10,7 @@ export const template = html `
|
|
|
9
10
|
@change="${(x, c) => x.changeHandler(c.event)}"
|
|
10
11
|
${children({
|
|
11
12
|
property: 'childTreeItems',
|
|
12
|
-
filter:
|
|
13
|
+
filter: node => isTreeItem(node),
|
|
13
14
|
})}
|
|
14
15
|
>
|
|
15
16
|
<slot></slot>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.template.js","sourceRoot":"","sources":["../../../src/tree/tree.template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"tree.template.js","sourceRoot":"","sources":["../../../src/tree/tree.template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAM;;;cAGpB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC/B,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAmB,CAAC;iBAC9C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAmB,CAAC;gBAC/C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAsB,CAAC;eACrD,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;MAC3C,QAAQ,CAAC;IACT,QAAQ,EAAE,gBAAgB;IAC1B,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;CACjC,CAAC;;;;CAIL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tree-item/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tree-item/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { attr, css, FASTElement, observable } from '@microsoft/fast-element';
|
|
3
|
+
import { toggleState } from '../utils/element-internals.js';
|
|
4
|
+
import { isTreeItem } from './tree-item.options.js';
|
|
5
|
+
export class BaseTreeItem extends FASTElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
/**
|
|
9
|
+
* The internal {@link https://developer.mozilla.org/docs/Web/API/ElementInternals | `ElementInternals`} instance for the component.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
this.elementInternals = this.attachInternals();
|
|
14
|
+
/**
|
|
15
|
+
* When true, the control will be appear expanded by user interaction.
|
|
16
|
+
* @public
|
|
17
|
+
* HTML Attribute: `expanded`
|
|
18
|
+
*/
|
|
19
|
+
this.expanded = false;
|
|
20
|
+
/**
|
|
21
|
+
* When true, the control will appear selected by user interaction.
|
|
22
|
+
* @public
|
|
23
|
+
* @remarks
|
|
24
|
+
* HTML Attribute: selected
|
|
25
|
+
*/
|
|
26
|
+
this.selected = false;
|
|
27
|
+
/**
|
|
28
|
+
* When true, the control has no child tree items
|
|
29
|
+
* @public
|
|
30
|
+
* HTML Attribute: empty
|
|
31
|
+
*/
|
|
32
|
+
this.empty = false;
|
|
33
|
+
this.childTreeItems = [];
|
|
34
|
+
this.elementInternals.role = 'treeitem';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Handles changes to the expanded attribute
|
|
38
|
+
* @param prev - the previous state
|
|
39
|
+
* @param next - the next state
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
expandedChanged(prev, next) {
|
|
44
|
+
toggleState(this.elementInternals, 'expanded', next);
|
|
45
|
+
if (this.childTreeItems && this.childTreeItems.length > 0) {
|
|
46
|
+
this.elementInternals.ariaExpanded = next ? 'true' : 'false';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Handles changes to the selected attribute
|
|
51
|
+
* @param prev - the previous state
|
|
52
|
+
* @param next - the next state
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
selectedChanged(prev, next) {
|
|
57
|
+
this.$emit('change');
|
|
58
|
+
toggleState(this.elementInternals, 'selected', next);
|
|
59
|
+
this.elementInternals.ariaSelected = next ? 'true' : 'false';
|
|
60
|
+
}
|
|
61
|
+
dataIndentChanged(prev, next) {
|
|
62
|
+
if (this.styles !== undefined) {
|
|
63
|
+
this.$fastController.removeStyles(this.styles);
|
|
64
|
+
}
|
|
65
|
+
this.styles = css `
|
|
66
|
+
:host {
|
|
67
|
+
--indent: ${next};
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
this.$fastController.addStyles(this.styles);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Handles changes to the child tree items
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
childTreeItemsChanged() {
|
|
78
|
+
this.empty = this.childTreeItems?.length === 0;
|
|
79
|
+
this.updateChildTreeItems();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Updates the childrens indent
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
updateChildTreeItems() {
|
|
87
|
+
if (!this.childTreeItems?.length) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.childTreeItems.forEach(item => {
|
|
91
|
+
this.setIndent(item);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets the indent for each item
|
|
96
|
+
*/
|
|
97
|
+
setIndent(item) {
|
|
98
|
+
const indent = this.dataIndent ?? 0;
|
|
99
|
+
item.dataIndent = indent + 1;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Handle focus events
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
focusHandler(e) {
|
|
107
|
+
if (e.target === this ||
|
|
108
|
+
// In case where the tree-item contains a focusable element, we should not set the tabindex to 0 when the focus is on its child focusable element,
|
|
109
|
+
// so users can shift+tab to navigate to the tree-item from its child focusable element.
|
|
110
|
+
this.contains(e.target)) {
|
|
111
|
+
this.setAttribute('tabindex', '0');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Handle blur events
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
blurHandler(e) {
|
|
120
|
+
if (e.target === this) {
|
|
121
|
+
this.setAttribute('tabindex', '-1');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Toggle the expansion state of the tree item
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
toggleExpansion() {
|
|
130
|
+
if (this.childTreeItems?.length) {
|
|
131
|
+
this.expanded = !this.expanded;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Toggle the single selection state of the tree item
|
|
136
|
+
*
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
toggleSelection() {
|
|
140
|
+
this.selected = !this.selected;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Whether the tree is nested
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
get isNestedItem() {
|
|
147
|
+
return isTreeItem(this.parentElement);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
__decorate([
|
|
151
|
+
attr({ mode: 'boolean' })
|
|
152
|
+
], BaseTreeItem.prototype, "expanded", void 0);
|
|
153
|
+
__decorate([
|
|
154
|
+
attr({ mode: 'boolean' })
|
|
155
|
+
], BaseTreeItem.prototype, "selected", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
attr({ mode: 'boolean' })
|
|
158
|
+
], BaseTreeItem.prototype, "empty", void 0);
|
|
159
|
+
__decorate([
|
|
160
|
+
attr({ attribute: 'data-indent' })
|
|
161
|
+
], BaseTreeItem.prototype, "dataIndent", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
observable
|
|
164
|
+
], BaseTreeItem.prototype, "childTreeItems", void 0);
|
|
165
|
+
//# sourceMappingURL=tree-item.base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-item.base.js","sourceRoot":"","sources":["../../../src/tree-item/tree-item.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