File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed
packages/components/src/tree-view Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 3
3
// Distributed under the terms of the Modified BSD License.
4
4
5
5
import {
6
+ isTreeItemElement ,
6
7
treeViewTemplate as template ,
7
- TreeView
8
+ TreeView ,
9
+ type TreeItem
8
10
} from '@microsoft/fast-foundation' ;
9
11
import { treeViewStyles as styles } from './tree-view.styles.js' ;
10
12
@@ -14,7 +16,41 @@ import { treeViewStyles as styles } from './tree-view.styles.js';
14
16
* @public
15
17
* @tagname jp-tree-view
16
18
*/
17
- class JupyterTreeView extends TreeView { }
19
+ class JupyterTreeView extends TreeView {
20
+ /**
21
+ * Handles click events bubbling up
22
+ *
23
+ * @internal
24
+ */
25
+ public handleClick ( e : Event ) : boolean | void {
26
+ if ( e . defaultPrevented ) {
27
+ // handled, do nothing
28
+ return ;
29
+ }
30
+
31
+ if ( ! ( e . target instanceof Element ) ) {
32
+ // not a tree item, ignore
33
+ return true ;
34
+ }
35
+
36
+ let item = e . target as Element | null ;
37
+ while ( item && ! isTreeItemElement ( item ) ) {
38
+ item = item . parentElement ;
39
+
40
+ // Escape if we get out of the tree view component
41
+ if ( item === this ) {
42
+ item = null ;
43
+ }
44
+ }
45
+
46
+ if ( item && ! ( item as TreeItem ) . disabled ) {
47
+ // Force selection - it is not possible to unselect
48
+ ( item as TreeItem ) . selected = true ;
49
+ }
50
+
51
+ return ;
52
+ }
53
+ }
18
54
19
55
/**
20
56
* A function that returns a {@link @microsoft/fast-foundation#TreeView } registration for configuring the component with a DesignSystem.
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ const Template: StoryFn = (args): HTMLElement => {
36
36
<jp-tree-item>Nested item 3</jp-tree-item>
37
37
</jp-tree-item>
38
38
<jp-tree-item expanded>
39
- Root item 2
39
+ Root <em style="padding: 0 0.2rem;"> item</em> 2
40
40
<jp-tree-item>
41
41
Flowers
42
42
<jp-tree-item disabled>Daisy</jp-tree-item>
You can’t perform that action at this time.
0 commit comments