Skip to content

Commit

Permalink
Merge pull request #1174 from smeup/tree-expansion-node-no-select
Browse files Browse the repository at this point in the history
tree: if KupTreeExpansionMode.NODE only expansion if expandible
  • Loading branch information
lucafoscili authored Oct 4, 2021
2 parents ecf9ab6 + 0994a60 commit 2eeff5c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
15 changes: 10 additions & 5 deletions packages/ketchup/src/assets/tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

document.addEventListener('kup-tree-nodeselected', (e) => console.log(e));
document.addEventListener('kup-tree-nodeexpand', (e) => console.log(e));
document.addEventListener('kup-tree-nodecollapse', (e) => console.log(e));
document.addEventListener('kup-tree-contextmenu', (e) => console.log(e));
document.addEventListener('kup-tree-columnmenu', (e) => console.log(e));
let treeData = [
Expand Down Expand Up @@ -190171,10 +190173,13 @@ if (treeLayoutFixedEl != null) {
console.log(JSON.stringify(detail));
onLoadData(detail);
});
treeLayoutFixedEl.addEventListener('kup-tooltip-loaddetail', ({ detail }) => {
console.log(JSON.stringify(detail));
onLoadDetailData(detail);
});
treeLayoutFixedEl.addEventListener(
'kup-tooltip-loaddetail',
({ detail }) => {
console.log(JSON.stringify(detail));
onLoadDetailData(detail);
}
);
}

function onLoadData(detail) {
Expand Down
47 changes: 28 additions & 19 deletions packages/ketchup/src/components/kup-tree/kup-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -957,32 +957,41 @@ export class KupTree {
auto: boolean
) {
unsetTooltip(this.tooltip);
// If this TreeNode is not disabled, then it can be selected and an event is emitted
if (
this.expansionMode.toLowerCase() ===
KupTreeExpansionMode.DROPDOWN ||
(this.expansionMode.toLowerCase() === KupTreeExpansionMode.NODE &&
!treeNodeData.expandable)
) {
// If this TreeNode is not disabled, then it can be selected and an event is emitted
if (treeNodeData && !treeNodeData.disabled) {
if (this.autoSelectionNodeMode)
this.selectedNode = treeNodePath
.split(',')
.map((treeNodeIndex) => parseInt(treeNodeIndex));

this.kupTreeNodeSelected.emit({
comp: this,
id: this.rootElement.id,
treeNodePath: treeNodePath
.split(',')
.map((treeNodeIndex) => parseInt(treeNodeIndex)),
treeNode: treeNodeData,
columnName: this.selectedColumn,
auto: auto,
});
}
this.selectedColumn = '';
}

// If KupTreeExpansionMode.NODE then click is a collapse/expand click
if (this.expansionMode.toLowerCase() === KupTreeExpansionMode.NODE) {
this.hdlTreeNodeExpanderClick(
treeNodeData,
treeNodePath,
e ? e.ctrlKey : false
);
}
if (treeNodeData && !treeNodeData.disabled) {
if (this.autoSelectionNodeMode)
this.selectedNode = treeNodePath
.split(',')
.map((treeNodeIndex) => parseInt(treeNodeIndex));

this.kupTreeNodeSelected.emit({
comp: this,
id: this.rootElement.id,
treeNodePath: treeNodePath
.split(',')
.map((treeNodeIndex) => parseInt(treeNodeIndex)),
treeNode: treeNodeData,
columnName: this.selectedColumn,
auto: auto,
});
}
this.selectedColumn = '';
}

// When a TreeNode must be expanded or closed.
Expand Down
1 change: 1 addition & 0 deletions packages/ketchup/src/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ <h1>Filters2</h1>
<kup-tree
global-filter
as-accordion
expansion-mode="node"
id="tree-show-filter2"
></kup-tree>
<h1>Filters3</h1>
Expand Down

0 comments on commit 2eeff5c

Please sign in to comment.