Skip to main content

Hug until container is too small

  • November 12, 2024
  • 3 replies
  • 123 views

Bethany_McBride_174

I would like an option to hug content until the container it is in is too small. For instance, I am making a tab bar where the tabs are set to fill so they adjust with screen sizes. The title on each has an info icon to the right. The text has to be set to hug for the icon to stay right next to the text. However, that means if the text is long, when the tabs shrink the text extends out rather than wrapping.

I would like the option to set the hugged text to wrap when it extends past the parent container without having to manually change it a each breakpoint.

Adam_Rodriguez

Have you tried max and min width sizes? This isn’t always the best but it does get the idea across in some cases.


UsabilityJeff

Ugh, I currently have a requirement for this too!

In my case, I am making labels for the Y-axis of a chart. It would be easy except that on hover there is fill color, so the frame of the text needs to “hug” the text.

Some labels can be quite long though, so they need to wrap to fit in the “label gutter” container. That is, the frame magically needs to turn to “fill” when the “label gutter” container responsively narrows.

My work around is to have two variations of the component, one for short labels that don’t need to wrap, and one for long ones that do, But this only partially works for a defined range of container widths, where all the short labels never need to wrap, and all the long labels never need to hug.


Bethany_McBride_174

Have you tried max and min width sizes? This isn’t always the best but it does get the idea across in some cases.

 

That is a good suggestion, but as you said not the best.

The problem with min-max widths as a workaround, is that it limits the reusability of the component. I could set the max width to the width of the current text, but then if we need to change the copy or use this in another area with different labels, then we would need the max width to change for each use case. 

 


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