Skip to main content
Question

How to retrieve componentPropertyDefinitions from team library component instance?


Brian_Alfaro1

I have my code running fine retrieving the componentPropertyDefinitions of local components I look up the mainComponent and find the componentSetNode and pull the property definitions there but when I try to pull it from an instance that is from a team library it fails to show it at all just empty javascript object and when I look at the parent node is not a componentSetNode but a page node?

Does anyone have any insight on this?

tank666
  • October 5, 2022

Could you share a code example?


Brian_Alfaro1
let nodes=figma.currentPage.selection;`

nodes.forEach((node)=>{
  if(node.type=="INSTANCE"){
    const ComponentSet=node.mainComponent.parent as ComponentSetNode;
    console.log(ComponentSet.componentPropertyDefinitions );
  }
})

Brian_Alfaro1

In that example, it works if the component is a local component but if its a component from a team library first the parent is not a componentNodeSet but rather a pageNode. When I run the plugin in the same file as the component that is in a team library it pulls the information with no issue.


tank666
  • October 5, 2022

Are you sure the instance you selected has a ComponentNodeSet parent? Maybe it’s just a ComponentNode?


Brian_Alfaro1

Yeah I am sure its a component node I drag the component from the Team library and literally just click it and run the plugin and it shows up as the node.maincomponent.parent is a pagenode rather than a componentSetNode. But When I try the same thing creating an instance of the same component in the local file it was created in it works. I honestly think it’s a bug in Figma because this outcome is not right and I am stumped


tank666
  • October 5, 2022

Sorry, but I can’t confirm this.

I created a file for you that has 4 component instances (2 from the library and 2 local).

Figma – 5 Oct 22

Please duplicate this file and test your plugin against it, then post your results.


Brian_Alfaro1

Idk what is different I did not change anything with my code but when I open your file it shows the component set and when I went back to my file it now shows as a component set and not a page node… 🤪 I guess solved? I have screenshots of it as a pagenode no matter what I did.

Oh well I will continue and I will return to this thread if I find the issue again with more insight thank you for your help


tank666
  • October 6, 2022

In my file, there are only 2 instances whose parent is ComponentSetNode. 2 more instances are instances of individual components that do not have component sets at all. That is, your code (which you provided above) should only print 2 results to the console for instances whose parent is ComponentSetNode.

By the way, I added 2 more instances to the file. And it would be great if you wrote about the results for each instance in order.


Brian_Alfaro1

Okay here the result individually

  1. When selected produces nothing in the console.
  2. When selected nothing is shown in the console.
  3. Shows property definitions in the console
  4. Shows property definitions in the console.

tank666
  • October 6, 2022

1 and 2. Don’t have a ComponentSetNode. The ComponentPropertyDefinitions is at the ComponentNode level.
3 and 4. Have a ComponentSetNode.
5 and 6. Have neither ComponentSetNode nor component properties.

That is, only instances 5 and 6 should have an empty object.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings