web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can text box width res...
Power Apps
Unanswered

Can text box width respond to length of text?

(0) ShareShare
ReportReport
Posted on by 221

As the title says, I am interested in making some of my text labels have responsive control width's depending on the length of text within them. I am using a function on the Fill property and it would look a lot better if the control it fills is only as long as the text of the selection made.

 

What would this width property function look like, is this even possible?

Categories:
I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    You would need to do something similar to this with a text box's width property

     

    If(Len(Self.Text)<100,
     320,
     Len(Self.Text)<200,
     440,
     Len(Self.Text)<300,
     540,
     640)

     

     

    Or even work out a mathematical formula based on len and how large you made your font for example

     

     

    If(Len(Self.Text)*10<100,100,Len(Self.Text)*10)

     

     

    Seems to work pretty well for Open Sans 13

  • Ginko Profile Picture
    221 on at

    Hi Rob, this is really cool, I've been playing with it and this works really well for the long item names.

    If(Len(Self.Text)*0<300,500,Len(Self.Text)*5)

     

    However, when item names are shorter than these specs, the formula doesn't apply well and makes for a wide box. I've been trying to make an Or, ||, && addition to the function but I'm clearly doing it wrong because nothing beyond the original function has an effect.

     

    Would you be able to help define what this function would look like if it took into consideration text that is both very long and shorter than the pre-defined measures? I hope that makes sense... 🙂

  • TheRobRush Profile Picture
    11,128 Moderator on at

    What I originally wrote already does account for short text,

    If(Len(Self.Text)*10<100,100,Len(Self.Text)*10)

    First portion, If Len(Self.Text) < 100, means if this text formula is shorter then 100 give it a minimum width of 100, can change that 100 to whatever works for you. 

     

    The way you have changed it to 

    If(Len(Self.Text)*0<300

    should always return to you a 500 width box since ANY number multiplied by 0 will always be less than 300.

     

     

  • Ginko Profile Picture
    221 on at

    @TheRobRush Okay to add onto my previous reply, I just found this works really well for the short text. How can I combine these two together to manage the min's and max's out there.

     

    Short Text - 
    
    If(Len(Self.Text)*100<100,100,Len(Self.Text)*12)
    
    Long Text - 
    
    If(Len(Self.Text)*0<300,500,Len(Self.Text)*5)
  • Verified answer
    TheRobRush Profile Picture
    11,128 Moderator on at

    There's too many issues with what you changed to combine them honestly

    For Example

    In

    If(Len(Self.Text)*100<100,100,Len(Self.Text)*12)

     

    Len(Self.Text)*100 - With this, even ten characters in a text box is going to be checking against a value of 1000, thats a massive number to chekc against for a 10 character string, very inaccurate.

     

    and in the second half

    If(Len(Self.Text)*0<300 

     

    Len(Self.Text)*0 will never have any other value than 0, so it will always come out as true, and therefore give you a width of 500 every single time.

     

    Here you will see I shortened short side a little for you , and brought down full size a bit 

    If(Len(Self.Text)*10<75,75,Len(Self.Text)*8.5)

     

    and here are several examples from 5 digits up to 100 to show it looks good with just this

    100 dig.PNGfifteen.PNGfive.PNGten.PNGthirty.PNGtwenty.PNG

  • Ginko Profile Picture
    221 on at

    Makes total sense, and I agree that does fit pretty darn well. I'm gonna use this but also just got this to work.

     

    If(Len(Self.Text)>45, 500, (If(Len(Self.Text)*100<100,100,Len(Self.Text)*9)))

     

    This is doing a good job first regulating my items that are super long, but then be kind to the shorter item names. Apologies if it sounds like I'm not listening (I am! haha) because I still have the *100 in there, but I think this meets the best of both worlds.

     

    Thank you so much for these functions, this is such an awesome transferable function to understand!

     

    Sean

  • kishoreitachi Profile Picture
    on at

    Need to expand width in textinput based on texinput words in power apps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard