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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can a component’s widt...
Power Apps
Answered

Can a component’s width change based on the controls inside it?

(0) ShareShare
ReportReport
Posted on by 466

I’m trying to create a reusable component in my Power App and need it’s width to change based on things like the length of the text in a label and whether certain icons are shown or not. If this were a normal container, I could just reference the width of all the objects inside the container, but I get errors when doing that with components.

 

For example, one copy of the component would have a label saying “ABC” and have a width of 10 while another copy of the same component would have a label saying “ABCDEF” and have a width of 15 to accommodate the label.

 

Can a component's width change dynamically based on what it contains?

Categories:
  • Verified answer
    v-yujincui-msft Profile Picture
    Microsoft Employee on at

    Hi @arpost,

     

    Do you want to make the width and height of component dynamic changes based on the strings within the labels?

    If you want to make the width and height of component dynamic changes based on the strings within the labels and ensure that its height and width do not exceed the screen,I am afraid that there is no directly way to achieve this in Power Apps currently.

    If you want to achieve this, it is necessary to set a limit for Height and Width of the Label, however, there is no way to set a Height limit for a AutoHeight property of the Label.The AutoHeight property  expects a Boolean value, if you want to set the maximum height for the Label control and the Container control, the data types will not match.

    If you only want to dynamically change the width of the component based on the strings within the labels while ensuring that its width does not exceed the screen, and you can accept to use the scroll bar to display all the strings in the label control.

    Here is an alternative solution for your reference.

     

    1.Add a Container Control.

    2.Add 3 Label Control and apply the following formula on its Width property as:

    If(25*Len(Label1.Text)>App.Width-140,550,If(Len(Label1.Text)=0, 25, 25*Len(Label1.Text)))

    3.Select the Label Control and apply the following formula on its Overflow property as:

    If(25*Len(Label1.Text)>App.Width-140,Overflow.Scroll,Overflow.Hidden)

    4.Select the Container Control and apply the following formula on its Width Property as:

    Max(If(Label1.Visible=true,Label1.Width),If(Label2.Visible=true,Label2.Width),If(Label3.Visible=true,Label3.Width),25)

     Result screenshots:

    ezgif-7-d796d02d73.gif

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 432 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 347

#3
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

Last 30 days Overall leaderboard