Hi,
I'm using the igx-tree for navigation purpose in my project - so far so good. But I'm facing with the situation when I expand a node the related node will be selected - like in the doc www.infragistics.com/.../tree
But this is a behavior that I don't want. My requirement is, that the user can click on the expand/collapse symbol but current selected node should not change.
How can I change this behavior.
THX
Hello,
From your description, it seems like you’re referring to the visual indication (border) around the nodes in the igx-tree component when they are selected. If your goal is to prevent the selected node's appearance from changing when expanding or collapsing other nodes, I recommend using a CSS approach to remove the border.
You can apply the following style to make the border transparent:
igx-tree { --igx-tree-border-color: transparent; }
This will ensure that no border is displayed when a node is clicked, preserving the visual state of the currently selected node even as others are expanded or collapsed.
The described scenario could be observed here:
For a practical demonstration, I’ve created a sample project where this styling is implemented. You can view it here: View Sample.
Please review the sample and let me know if it meets your requirements or if there are any additional customizations you’d like to discuss. I’m happy to help with any further adjustments or questions!
Regards,
Georgi Anastasov
Entry Level Software Developer
Infragistics
Hello Georgi,
Thanks for you quick reply.
Unfortunatally it is not only the visual indication of the border. When I expand/collapse the node I also receive the "activeNodeChanged" event which leads to corresponding actions being carried out.
However, this is exactly what I don't want if the user only wants to expand/collapse the node.
The action shall be performed only if the node was clicked/selected but not if the node will only expand/collapse by the user (click on the expand/collapse symbol)
Hazim
First of all, I'd like to clarify that the behavior you're experiencing with the igx-tree component is by design. The activeNodeChanged event is triggered both when the user clicks on the expand/collapse icon as well as when they click on the node itself. This means it's not possible to prevent the activeNodeChanged event from firing when the expand/collapse icon is clicked.
However, you can differentiate between these actions in your event handling logic. Here's a recommended approach to achieve the desired functionality:
Step 1: Handle activeNodeChanged Event
Add the activeNodeChanged event handler to the igx-tree component as shown below:
<igx-tree class="tree-root" (activeNodeChanged)="onActiveNodeChanged($event)"> </igx-tree>
In this setup, the activeNodeChanged event is fired whenever the active node changes, regardless of whether the change is due to a node click or an icon click.
Step 2: Handle Expand/Collapse Icon Click Separately
Within the ng-template of the igxTreeExpandIndicator directive, you can add an igx-icon component with a click event handler. This will allow you to determine if the expand/collapse icon was clicked:
<ng-template igxTreeExpandIndicator let-expanded> <igx-icon (click)="onExpandIconClick(expanded)"> {{ expanded ? "expand_more" : "chevron_right" }} </igx-icon> </ng-template>
By using this approach, you can track whether the user clicked the expand/collapse icon specifically, allowing for differentiated logic.
Step 3: Use a Flag to Determine Actions
In your TypeScript file, use a private flag expandIconClicked to track whether the icon was clicked. Here’s the updated logic:
public data = DATA; private expandIconClicked = false; constructor() {} public onExpandIconClick(expanded: boolean): void { if (!expanded) { // Mark that the expand icon was clicked this.expandIconClicked = true; } } public onActiveNodeChanged(event): void { setTimeout(() => { if (this.expandIconClicked) { // Prevent the default action if expand icon was clicked console.log('Node was expanded/collapsed with the icon, no further action needed.'); this.expandIconClicked = false; // Reset the flag } else { // Perform actions if the node was clicked console.log('Node was clicked and active, performing actions.'); // Insert your action logic here } }, 100); }
Summary of the Logic:
This approach will help you differentiate between node clicks and expand/collapse actions, allowing you to control the behavior accordingly.
Live Example:
I've created a sample project that demonstrates this approach. You can check it out and see the implementation in action here: StackBlitz Example.
If you have any further questions or need additional support, please feel free to reach out.
Thanks for the answer and a possible solution and the demo!
Unfortunately, this approach does not work for my application because I use the tree for navigation and therefore show and hide tabs dynamically on the right-hand side. The user only wants to expand (to see the childs), but the selection should not be changed because the views shall stay while expanding (showing the childs).
You write that the behavior as it is, is by design (and it's different form JQuery Ignite UI as far as I remember) - then unfortunately nothing what I can do.
Thank you and best regards
Thank you for your detailed feedback and for explaining your specific use case. I understand that the proposed workaround doesn't fully meet your requirements since you're using the igx-tree component for navigation and need to maintain the current selection when expanding or collapsing nodes. You want the user's view to remain unchanged while they explore the tree structure.
Given that the current behavior of the igx-tree is by design and differs from the jQuery Ignite UI implementation you're familiar with, I recommend submitting a feature request to our development team. This way, they can consider enhancing the component to better accommodate scenarios like yours.
You can submit a feature request in our GitHub repository for Ignite UI for Angular here: https://github.com/IgniteUI/igniteui-angular/issues
When submitting your feature request, please provide as much detail as possible to help our team understand your needs. Here are some guidelines to assist you:
Additional Tips:
By submitting this feature request, you'll have a direct line of communication with our developers. They'll review your proposal, discuss its feasibility, and consider it for future releases of the igx-tree component.
If you need any assistance while creating the feature request or have further questions, please feel free to reach out. I'm here to support you in any way I can.