vue3-tree-vue icon indicating copy to clipboard operation
vue3-tree-vue copied to clipboard

Avoid events (onExpand and ocCollapse)) when the expand-option is controller programatically

Open SciManJD opened this issue 5 months ago • 5 comments

Hi, I'm trying to find a way how I can skip the events when the expand or collapse of a node is made from my code. I need the events just when somebody is actively clicking on the expanders. So far, no success. Is there a way to do this? Thanks in advance!

SciManJD avatar Jul 09 '25 11:07 SciManJD

Hi, I'm trying to find a way how I can skip the events when the expand or collapse of a node is made from my code. I need the events just when somebody is actively clicking on the expanders. So far, no success. Is there a way to do this? Thanks in advance!

Can you please share some code samples I can reproduce with ?

geekhybrid avatar Jul 09 '25 11:07 geekhybrid

Here is the tree (of course it is simplified a lot):

<vue3-tree-vue  
        :items="modifiedItems"
        :isCheckable="false"
        :hideGuideLines="false"
        v-model:selectedItem="selectedDevice"
        @onSelect="getSelectedNode"
        @onExpand="setCustomLevel"
        @onCollapse="setCustomLevel"
        @dropValidator="copyDeviceParams">
</vue3-tree-vue>

I have also a function that sets the property "expanded" of the nodes in the tree object to true or false, depending on settled expand level (because my device tree has several levels). But when I call this function, the events onExpand or onCollapse are generated many times (on each change of a property "expanded". And these events are calling the function setCustomLevel() and this I want to avoid. The meaning of this function is just to detect if the settled expand level that was given to my function was manually changed (by direct click on the user on the expanders).

I don't think that this is a bug. Probably this is an expected behavior. I just want to find a way to solve my problem.

SciManJD avatar Jul 09 '25 12:07 SciManJD

I solved the problem, but I really don't like my solution. Unfortunately I couldn't find a better one. When I programmatically change the property "expanded", I count how many time I do this. Then in the function setCustomLevel() I decrease by 1 this counter until it reaches 0. Only if it is 0, I decide that this is a human interaction.

SciManJD avatar Jul 09 '25 13:07 SciManJD

It doesn't work stable in some cases.

SciManJD avatar Jul 09 '25 14:07 SciManJD

I am split 50-50 between whether to treat this as a bug (in which case we should fix it on the component) or it's something that you may want to find a way to handle on the application layer.

geekhybrid avatar Jul 18 '25 19:07 geekhybrid