+ Start a Discussion

Unable to add selected custom class for <lightning:tree>

We have a lightning tree structure instead of a lookup field. And when the user selects the any values. And again click on the dropdown list.
The selected item should be highligted. The same thing even in edit page. Unable to add class to teh selected.
Below is the code for the same.
Component code
 <lightning:tree aura:id="MyCustomId" class="MyCustomClass" items="{!v.items}" onselect="{!c.handleSelect}" />
JS code
handleSelect : function (cmp, event, helper) {
       $A.util.addClass(event.getParam('name'), "slds-is-selected");
var childCmp = cmp.find("MyCustomId");
        var btnClicked = event.getSource();

User-added image
NagendraNagendra (Salesforce Developers) 

You can try creating custom tree component and achieve this feature as it's not supported in the standard lightning:tree as of yet.
Note : Selection is highlighted based on aria-selected="true" .

Hope this helps.

Kindly mark this as solved if the information is helpful.

Thanks Nagendra fro reply. But we were trying to selt that aria-selected="true"  from apex class when we prep the list for those tree. But we were not able to and left there with the limitation. It works when you manuaully click. But you can't set that dynamically