Accessing Instance props (getProps) when using figma.children()
Good day!
Similar to https://github.com/figma/code-connect/issues/215, our designer is also using Icons as children instead of instance swap properties.
Is it possible to use the getProps on this result to get the properties of this mapped instance?
Figma
What I'd like to do
figma.children('*').getProps<{ name: string }>()
Similar to
figma.instance('icon').getProps<{ name: string }>()
Note: when there is an instance swap property, figma.instance('icon').getProps<{ name: string }>() does work but this specific component in Figma does not have one.
What it looks like now
<Badge icon={<Icon icon="IconName" size={16} />} />
What I would like it to be
<Badge icon="IconName" />
Please provide:
- Code Connect CLI version [use npx figma -V if using React, or figma -V otherwise, to get the version of your CLI]
- 1.2.4
- Operating system
- macOS 15.2 (25C101)
Thanks for the help!
This is similar to https://github.com/figma/code-connect/issues/215 but i am unsure if this will be resolved at the same time.
Hello! Just checking in on this one. Thank you
Hey @blabute! Thanks for the report - this is a limitation with our API at the moment, as getProps can only be used on the instance() helper. We're thinking about how we can expand this to be compatible with children() too but currently there isn't a workaround for this case I'm afraid
Hello @slees-figma! Thanks for the information. We look forward to that functionality!
Somewhat related, does nestedProps support using a wildcard (*) for the layerName like children does? We've got a setup that works using nestedProps, but the layer name can be different depending on the Icon being used so wanted to explore that. From my testing, nestedProps does not support using a wildcard for the layerName.
Hey @blabute, that's right unfortunately, the wildcard option is only available on figma.children right now
Thanks, @slees-figma! I appreciate the quick response!
In case anyone comes across this and the feature is not yet available, as a workaround, my team is:
- Using
nestedPropsand has renamed the "layer" of the Icon to be "icon". Even if the designer updates the instance of the icon to be a different icon, the layer name persists. - Added a property to each Icon named "name" that uniquely identifies the Icon.
- Maps the icon name in Figma to our Icon name in code like in the below.
figma.nestedProps('icon', {
name: figma.enum('name', {
...
})
})