Skip to main content
Answer

Issue applying max-width and max-height properties for text layers in auto-layout using plugin API

  • August 20, 2024
  • 2 replies
  • 160 views

Leon10

I’m developing a Figma plugin that pastes frames onto the canvas using the Plugin API. The frames are structured in JSON format and include nested auto-layout frames with text layers inside them. These text layers are set to “hug” content with specified max-height and max-width properties.

When pasting the frames, all elements are translated and positioned correctly. The text layers are nested within the auto-layout frames and have the layout value set to “hug.” However, the max-width and max-height properties are not being applied as expected.

The Figma app console displays the following error:
“Error applying maxHeight: Error: in set_maxHeight: Can only set maxHeight on auto layout nodes and their children.”

Has anyone else encountered similar issues or found a solution to this? Could this be a bug or a limitation within the Plugin API?

Best answer by James_Yang

The frames are structured in JSON format

Is it possible that when you’re iterating through the keys of the JSON, you’re setting maxHeight before applying auto-layout to the frame?

For example, the below code will fail, but if you switch the order of the last 2 lines, then it works.

const frame = figma.createFrame()
frame.maxHeight = 100
frame.layoutMode = 'VERTICAL'
This topic has been closed for replies.

2 replies

James_Yang
Figmate
  • Figmate
  • Answer
  • August 21, 2024

The frames are structured in JSON format

Is it possible that when you’re iterating through the keys of the JSON, you’re setting maxHeight before applying auto-layout to the frame?

For example, the below code will fail, but if you switch the order of the last 2 lines, then it works.

const frame = figma.createFrame()
frame.maxHeight = 100
frame.layoutMode = 'VERTICAL'

Leon10
  • Author
  • September 2, 2024

Thanks a lot James. Issue was indeed that maxHeight needed to be set after initial frame creation.