code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

[HTML] nestedProps doesn't seem to work

Open massi08 opened this issue 1 year ago • 8 comments

  • Code Connect CLI version [use npx figma -V if using React, or figma -V otherwise, 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

massi08 avatar Sep 27 '24 12:09 massi08

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.

ericandrewscott avatar Oct 02 '24 11:10 ericandrewscott

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.

massi08 avatar Oct 02 '24 12:10 massi08

Could you use figma.children?

ericandrewscott avatar Oct 02 '24 13:10 ericandrewscott

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.

massi08 avatar Oct 02 '24 13:10 massi08

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.

tomduncalf-figma avatar Oct 02 '24 14:10 tomduncalf-figma

Thanks, @tomduncalf-figma. You can check for figma.instance as well because I never managed to make it work

massi08 avatar Oct 02 '24 14:10 massi08

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

tomduncalf-figma avatar Oct 02 '24 14:10 tomduncalf-figma

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.

massi08 avatar Oct 02 '24 14:10 massi08

Hi all, we've released a fix for this in please v1.2.0. Please let us know if you encounter further issues.

slees-figma avatar Oct 16 '24 14:10 slees-figma