Skip to main content
Solved

Constraints are being outputted incorrectly


Eddie_Herrera

Greetings, I have been using the Figma API for a while now and started experimenting with more specific things. In doing so, I found a potential bug relating to how constraints are represented in the Figma design file to what is coming out from the API.

For example, take the following “Colleges Group.”

The constraints seem to be:
Horizontal.Right and Vertical.Top;
However, this is what I am presented with when doing an HTTP command using cURL:

I am presented with:
Horizontal.LEFT and Vertical.TOP

Thank you in advance!

Best answer by Gleb

Groups don’t have constraints, in the properties panel they show constraints of the nested items. Therefore it’s an error that constraints are present here at all. However, the default value is top left, and since there is no way to change it in the file, this value is shown in the REST API output.

View original

7 replies

Gleb
  • Power Member
  • 4706 replies
  • Answer
  • July 30, 2021

Groups don’t have constraints, in the properties panel they show constraints of the nested items. Therefore it’s an error that constraints are present here at all. However, the default value is top left, and since there is no way to change it in the file, this value is shown in the REST API output.


Eddie_Herrera

Awesome! Thanks for the fast reply Gleb!


Eddie_Herrera

Actually, Gleb, to make sure I understand it correctly. The group would reflect the constraints from the nested elements? If so, wouldn’t it become one of the following constraints? Or am I missing something? 🧐:

Nested Elements:
image

The simplePaperIcon:
with constrains: V.Scale | H.Scale
image

Colleges:
with constrains: V.Bottom | H.LeftAndRight
image

and Background:
with constrains: V.Scale | H.Scale
image

Again, Thanks for your help!


Gleb
  • Power Member
  • 4706 replies
  • July 30, 2021

You have a group called “Group 2 Copy 2” and inside of it you don’t have the objects you mentioned, you have one frame object called “Group”, and frames can have constraints so “Group 2 Copy 2” reflects constraints set on that frame.


Eddie_Herrera

Ah, I think I got it! I think the only thing that confused me was the difference between what comes out in the JSON to that of the editor. In the editor, the “Group 2 Copy 2” does inherit the constraints of the “Group” frame; however, in the JSON “Group 2 Copy 2” does present the default values and does not inherit that of “Group” 🤔


Gleb
  • Power Member
  • 4706 replies
  • July 30, 2021

That’s correct. The group in the editor (and in code) doesn’t actually inherit any properties from its children. It simply shows them in the properties panel when possible (e.g. constraints, color, etc.).


Eddie_Herrera

Got it! Thank you, Gleb! 😃


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