-
Notifications
You must be signed in to change notification settings - Fork 79
fix(tree-item): updates state when selection changes programmatically for selection-mode='ancestors'
#7572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tree-item): updates state when selection changes programmatically for selection-mode='ancestors'
#7572
Changes from 9 commits
603364e
887e649
ed590f9
7c51255
aa33c0a
5e4d527
8f1f652
ee0c192
e302686
c2d26e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,11 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
/** When `true`, the component is expanded. */ | ||
@Prop({ mutable: true, reflect: true }) expanded = false; | ||
|
||
@Watch("expanded") | ||
expandedHandler(newValue: boolean): void { | ||
this.updateParentIsExpanded(this.el, newValue); | ||
} | ||
|
||
/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */ | ||
@Prop({ reflect: true }) iconFlipRtl: FlipContext; | ||
|
||
|
@@ -69,9 +74,18 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
/** When `true`, the component is selected. */ | ||
@Prop({ mutable: true, reflect: true }) selected = false; | ||
|
||
@Watch("expanded") | ||
expandedHandler(newValue: boolean): void { | ||
this.updateParentIsExpanded(this.el, newValue); | ||
@Watch("selected") | ||
handleSelectedChange(value: boolean): void { | ||
if (this.selectionMode === "ancestors" && !this.userInteracted) { | ||
if (value) { | ||
this.indeterminate = false; | ||
} | ||
this.calciteInternalTreeItemSelect.emit({ | ||
modifyCurrentSelection: true, | ||
forceToggle: false, | ||
updateTarget: false, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -330,7 +344,9 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
this.calciteInternalTreeItemSelect.emit({ | ||
modifyCurrentSelection: this.selectionMode === "ancestors" || this.isSelectionMultiLike, | ||
forceToggle: false, | ||
updateTarget: true, | ||
}); | ||
this.userInteracted = true; | ||
} | ||
|
||
iconClickHandler = (event: MouseEvent): void => { | ||
|
@@ -353,9 +369,11 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
if (this.selectionMode === "none") { | ||
return; | ||
} | ||
this.userInteracted = true; | ||
this.calciteInternalTreeItemSelect.emit({ | ||
modifyCurrentSelection: this.isSelectionMultiLike, | ||
forceToggle: false, | ||
updateTarget: true, | ||
}); | ||
event.preventDefault(); | ||
break; | ||
|
@@ -368,13 +386,16 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
el.matches("a") | ||
) as HTMLAnchorElement; | ||
|
||
this.userInteracted = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking for a better name here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should set some guidelines for this as this pattern is becoming more frequent and we have a couple names in place:
Maybe |
||
|
||
if (link) { | ||
link.click(); | ||
this.selected = true; | ||
} else { | ||
this.calciteInternalTreeItemSelect.emit({ | ||
modifyCurrentSelection: this.isSelectionMultiLike, | ||
forceToggle: false, | ||
updateTarget: true, | ||
}); | ||
} | ||
|
||
|
@@ -429,6 +450,8 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
// | ||
//-------------------------------------------------------------------------- | ||
|
||
@State() hasEndActions = false; | ||
|
||
/** | ||
* Used to make sure initially expanded tree-item can properly | ||
* transition and emit events from closed state when rendered. | ||
|
@@ -437,15 +460,15 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
*/ | ||
@State() updateAfterInitialRender = false; | ||
|
||
actionSlotWrapper!: HTMLElement; | ||
|
||
childrenSlotWrapper!: HTMLElement; | ||
|
||
defaultSlotWrapper!: HTMLElement; | ||
|
||
actionSlotWrapper!: HTMLElement; | ||
|
||
private parentTreeItem?: HTMLCalciteTreeItemElement; | ||
|
||
@State() hasEndActions = false; | ||
private userInteracted = false; | ||
|
||
//-------------------------------------------------------------------------- | ||
// | ||
|
@@ -474,7 +497,6 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
*/ | ||
private updateAncestorTree(): void { | ||
const parentItem = this.parentTreeItem; | ||
|
||
if (this.selectionMode !== "ancestors" || !parentItem) { | ||
return; | ||
} | ||
|
@@ -492,6 +514,15 @@ export class TreeItem implements ConditionalSlotComponent, InteractiveComponent | |
} else if (selectedSiblings.length > 0) { | ||
parentItem.indeterminate = true; | ||
} | ||
|
||
const childItems = Array.from( | ||
this.el.querySelectorAll<HTMLCalciteTreeItemElement>("calcite-tree-item:not([disabled])") | ||
); | ||
|
||
childItems.forEach((item: HTMLCalciteTreeItemElement) => { | ||
item.selected = true; | ||
item.indeterminate = false; | ||
}); | ||
} else if (this.indeterminate) { | ||
const parentItem = this.parentTreeItem; | ||
parentItem.indeterminate = true; | ||
|
Uh oh!
There was an error while loading. Please reload this page.