You need to sign in to do that
Don't have an account?
M.sf
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");
alert('childCmp->'+childCmp);
var btnClicked = event.getSource();
alert('btnClicked->'+btnClicked);
$A.util.toggleClass(childCmp,'MyCustom-selected');
*/
}
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');
*/
}
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