Skip to content

Conversation

@sfc-gh-lwilby
Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby commented Oct 22, 2025

Describe your changes

Content width containers will size themselves based on the content you place inside.

Screenshot 2025-10-22 at 6 20 08 PM Screenshot 2025-10-22 at 6 19 42 PM

Note: If you are using elements with width="stretch" inside of a container with width="content" then some elements will shrink to their minimum size. Use fixed widths or content width on these elements to render them larger.

Example: maps don't have a defined content width so they will render at the minimum width. Define a larger fixed width value to make them bigger when inside a content width container!

Screenshot 2025-10-22 at 6 19 11 PM

This is similar for dataframes. Use width=content or a fixed width to show the entire dataframe when inside a content width container.

Screenshot 2025-10-22 at 6 19 03 PM Screenshot 2025-10-24 at 1 27 35 PM

GitHub Issue Link (if applicable)

Testing Plan

  • Unit Tests (JS and/or Python) ✅
  • E2E Tests ✅
  • Manual testing of minimum width and other cases for elements not covered in e2e tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Oct 22, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12848/streamlit-1.50.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12848.streamlit.app (☁️ Deploy here if not accessible)

> & {
node: ElementNode
}
> = ({ node, ...rest }) => {
const { isInHorizontalLayout } = useRequiredContext(FlexContext)

let minStretchBehavior: MinFlexElementWidth = "fit-content"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default for minStretchBehavior is now determined in useLayoutStyles only.

@sfc-gh-lwilby sfc-gh-lwilby added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Oct 22, 2025
@sfc-gh-lwilby sfc-gh-lwilby force-pushed the feature/content-width-on-container branch from e8ab812 to a7b4028 Compare October 22, 2025 16:57
@sfc-gh-lwilby sfc-gh-lwilby force-pushed the feature/content-width-on-container branch from 6da4b36 to 336c094 Compare October 24, 2025 11:17
@sfc-gh-lwilby sfc-gh-lwilby marked this pull request as ready for review October 24, 2025 12:15
Comment on lines 233 to 234
// Buffer to account for padding/margins (in pixels)
const PADDING_BUFFER = 32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This should either be defined outside of the scope of this function, or added as an optional argument with a default set to 32

}

export type MinFlexElementWidth = "fit-content" | "14rem" | "8rem" | undefined
export type MinFlexElementWidth = "14rem" | "8rem" | "fit-content" | undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Seems like an unnecessary change. Consider reverting this to maintain a smaller diff.

"""Snapshot test for the container with map in st_layouts_container_various_elements.py."""

# Wait for map elements to load
# Wait for map elements to load (now we have 2 maps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider reworking this comment and the one above so that they are more durable over time, rather than referencing a change that was made in this specific commit.

)
st.map(map_data, width="stretch")

# fixed width container with width 100 and a dataframe inside with stretch width
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment '# fixed width container with width 100 and a dataframe inside with stretch width' violates the Python Guide rule that requires comments to be capitalized, use proper grammar and punctuation. The comment should start with a capital letter: '# Fixed width container with width 100 and a dataframe inside with stretch width.'

Suggested change
# fixed width container with width 100 and a dataframe inside with stretch width
# Fixed width container with width 100 and a dataframe inside with stretch width

Spotted by Graphite Agent (based on custom rule: Python Guide)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +234 to +236
if (parentWidth < minWidthInPixels && parentWidth > buffer) {
return `${parentWidth - buffer}px`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a safeguard for when parentWidth is less than or equal to buffer, which would result in a negative or zero width. This edge case should be handled to ensure the calculated width is always positive:

if (parentWidth < minWidthInPixels && parentWidth > buffer) {
  return `${parentWidth - buffer}px`
} else if (parentWidth <= buffer) {
  // Return a small minimum width when parent is extremely narrow
  return "1px" // or some other reasonable minimum
}
Suggested change
if (parentWidth < minWidthInPixels && parentWidth > buffer) {
return `${parentWidth - buffer}px`
}
if (parentWidth < minWidthInPixels && parentWidth > buffer) {
return `${parentWidth - buffer}px`
} else if (parentWidth <= buffer) {
// Return a small minimum width when parent is extremely narrow
return "1px" // or some other reasonable minimum
}

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@sfc-gh-lwilby sfc-gh-lwilby merged commit 5409b98 into develop Oct 29, 2025
38 of 40 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the feature/content-width-on-container branch October 29, 2025 14:50
sfc-gh-nbellante added a commit that referenced this pull request Oct 31, 2025
…ments_test

Skip on Chromium due to 1px snapshot width mismatch in CI. See failing workflow: https://github.com/streamlit/streamlit/actions/runs/18964912763/job/54180100557\n\nRecent snapshot touched by 9d3a016 (#12891); feature introduced in 5409b98 (#12848). We'll stabilize and re-enable later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants