Closed softmarshmallow closed 3 years ago
Thanks for reporting! This seems to be a documentation error, not a typings error. Groups indeed don't support constraints, only children of groups.
But surely in the figma editor, Group does support constraints intuitively like others. Why is this designed this way, and how do i get the constraints of the group?
I believe every node except boolean operator and slice should have a constraint property seamlessly.
Thanks.
@rudi-c Do i calculate the Group nodes constraint by it's children's constraints?
not a correct syntax, just making my point
const isGroupConstraintLeft = node.children.foreach((c) => {c.constraints.horizontal == "MIN"})
But if i do it this way, It get's alot dirty. I Have to check if The group is nested, I'll have to check to the bottom of the tree which having the constraints property.
How does figma plugin handles it?
Groups are kind of like a folder. They group layers together in the layers panel, but as far as the behavior on the canvas is concerned, it's as if they weren't there.
When you select groups, it looks like they have properties in the properties panel, but it's really just showing the properties of the group's children.
Alright. Can you answer my second question?
To check group's constraint iterating though child seems like a absurd job.
Maybe it's something api should provide for developer's convenience.
Also, we need explanation for difference between design of frame and group.
If we had such an API, it would have to return MIXED when children have different constraint which means in many uses cases, you'd have to traverse through the children anyway to find out what the different constraints are. Generally speaking, we don't include helper functions in the API that are easy for the developer to implement and would be redundant. The larger the API surface, the larger the bug surface area and more importantly, the more risk of breaking plugins due to backwards-incompatible changes. Those types of helper functions can be imported and belong in places such as https://github.com/figma-plugin-helper-functions/figma-plugin-helpers
https://www.figma.com/best-practices/groups-versus-frames/
referencing for future readers.
Thanks @rudi-c
https://www.figma.com/plugin-docs/api/GroupNode/#constraints
but not found in plugin typings. v1.17.1
does not contains constraint mixin.