[HTML] nestedProps doesn't seem to work
- Code Connect CLI version [use
npx figma -Vif using React, orfigma -Votherwise, to get the version of your CLI] 1.1.3 - Operating system MacOs
Issue:
If i understood correctly, figma.nestedProps allows us to access child components/layers props from the parent. But i get errors that the child layer is not found.
Here is how i use it:
props: {
labelChild: figma.nestedProps('Label', {
label: figma.string("Label"),
}),
},
example: (props) => html`
<component>
<sub-component>${props.labelChild.label}</sub-component>
</component>
`
I get this error:
undefined: Could not find prop mapping for labelChild.label
I have checked that the name of the sub layer is correct and tried renaming it to something different in both code and figma, but i am still encountering the same issue. I also tried with a figma.boolean or figma.enum
Have you tried figma.textContent() instead of figma.string?
If you are trying to read a prop on subcomponent called Label where the prop is also called Label, that should work.
If you are trying to read text in a node called Label on a subcomponent called Label, that won't work.
It is indeed a prop, I gave the exemple with a string prop but I also tried with a boolean or enum prop and it doesn't work.
Could you use figma.children?
Yes on other examples I used figma.children and it worked great.
However I never had success with figma.instance or figma.nestedProps.
In the case above if I use figma.children it shows the code related to the sub component.
But I do not want to use figma.children because the sub component "Label" is used in multiple form items and its selector varies depending on the context in which it is used.
There are many other use cases where I want to access a child component props instead of just displaying it with figma.children, for e.g: In some cases, child component props are overridden by the parent and we do not want to display these props on the child component when used in this context.
Hey @massi08, apologies for the delay responding here and the inconvenience. It looks like there is a bug with nestedProps in the HTML API, I was able to reproduce this – we will get this fixed and notify you when there's an update.
Thanks, @tomduncalf-figma. You can check for figma.instance as well because I never managed to make it work
I just tried figma.instance and it worked for me – can you describe how you're trying to use it? It's just for use with instance swap properties
I cannot remember the exact exemple but it was an attempt because figma.nestedProps was not working. If I happen to come across this issue again I will open a separate github issue.
Hi all, we've released a fix for this in please v1.2.0. Please let us know if you encounter further issues.