Skip to main content

Notifications

Community site session details

Community site session details

Session Id : Ldap7/k13GjKehx14J3vYH
Power Apps - Building Power Apps
Answered

Can text box width respond to length of text?

Like (0) ShareShare
ReportReport
Posted on 4 Jun 2022 00:47:39 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?

  • kishoreitachi Profile Picture
    on 14 Feb 2024 at 07:12:10
    Re: Can text box width respond to length of text?

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

  • Ginko Profile Picture
    221 on 06 Jun 2022 at 21:24:55
    Re: Can text box width respond to length of text?

    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

  • Verified answer
    TheRobRush Profile Picture
    11,121 Super User 2025 Season 1 on 06 Jun 2022 at 20:21:42
    Re: Can text box width respond to length of text?

    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 06 Jun 2022 at 20:06:44
    Re: Can text box width respond to length of text?

    @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)
  • TheRobRush Profile Picture
    11,121 Super User 2025 Season 1 on 06 Jun 2022 at 19:57:45
    Re: Can text box width respond to length of text?

    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 06 Jun 2022 at 19:42:45
    Re: Can text box width respond to length of text?

    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,121 Super User 2025 Season 1 on 04 Jun 2022 at 02:54:25
    Re: Can text box width respond to length of text?

    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

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started