1

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");
    alert('childCmp->'+childCmp);
    var btnClicked = event.getSource();
    alert('btnClicked->'+btnClicked);
    $A.util.toggleClass(childCmp,'MyCustom-selected');
  */
}

enter image description here

  • Component code <lightning:tree aura:id="MyCustomId" class="MyCustomClass" items="{!v.items}" onselect="{!c.handleSelect}" /> – M.sf Feb 27 '18 at 9:21
1

You can try creating custom tree component and achieve this feature as it's not supported in the standard lightning:tree as of yet : https://www.lightningdesignsystem.com/components/trees/

Note : Selection is highlighted based on aria-selected="true" .

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.