Skip to main content
Arthur_Arakelian
May 26, 2022
Question

Customize "Fixed width" of the nested instance

  • May 26, 2022
  • 19 replies
  • 17902 views

Hey there 👋 …is there a way to set a custom “Fixed width” for a nested instance of the component?

currently i’m just creating other master component (just one level higher) with the necessary width, but i’d like to avoid this method as i have to create new master each time which i think is not a good solution. So i’d like to know if there any other optimal way to set custom width for the nested instance.

This topic has been closed for replies.

19 replies

Isaiah_Goodfriend
May 9, 2024

Brilliant! Thanks for sharing this gem, Alice 👏

Pavlo_Kiselov
Active Member
May 9, 2024

It’s definitely nice one. After some time I got something slightly better if you like. Instead of drilling down layers I found it’s more convenient to have configurable width property instead

This way I can quickly set the size of an element to a specific value.


Here how it works

On top level this is a container for anything I like, in this particular it’s a form element that sits inside auto sized container. There are two props, one is to select specific input type and another one to adjust the width

Form Control component fills the width

The most important part is a width component. It’s like size tokens in TailwindCSS

As you can see it’s exactly the same spacer. I just made bunch of them to get as many sizes as I need

Here is some live action

Yay or nay? )

Isaiah_Goodfriend
May 9, 2024

A nice touch for sure. I’m using this primarily to adjust table columns, which requires me to input the width values manually.

AlicePackard
Power Member
May 10, 2024

Pavlo, your implementation is excellent! Using a swap property (and not variants in a single component set) also ensures this is still a layer-efficient approach. Your solution is also great for a team that’s using pre-defined styles (like tailwind). Appreciate you taking the time to include all those screenshots and video recording, I think this will help lots of folks out who discover this thread 💪

I write about building excellent Figma components on my blog: https://alicepackarddesign.com/blog
Pavlo_Kiselov
Active Member
May 10, 2024

Thanks Alice. This method found its way to many many components in our design system. And yes, it’s much more effective than variants indeed. Also it’s a treat for the devs, they know exactly how much space is required without digging down layers

AlicePackard
Power Member
May 10, 2024

Making devs happy is always a win 🥰

I write about building excellent Figma components on my blog: https://alicepackarddesign.com/blog
Peter_Tschann-Grimm
July 18, 2024

I cannot get this to work! I have the containers setup the same way but when I change the instance of the spacer, nothing happens. It stays the same default width 😦

Pavel_Kiselev
Power Member
July 18, 2024

Is your spacer set to hug contents sizing? The trick here is to have all spacers not a fix size, but have an element inside instead.

Peter_Tschann-Grimm
July 18, 2024

Thank you! I did! I didn’t realize it had to be with the horizontal gap as the thing that determines the width