fix(select): prevent content overflow with max-w-min #2208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
The Select component had a UX issue where dropdown content with long text would expand beyond the trigger's width, creating an inconsistent and unprofessional appearance. This created a poor user experience, especially in scenarios where:
w-[120px])The issue manifested as the dropdown being much wider than the trigger button, creating a jarring visual disconnect.
Solution Discovery Process
During the investigation, I experimented with several CSS approaches to solve this width consistency issue:
w-max- Initially tried to let the content width grow to fit its content, but this didn't play well with the existing min-width constraint frommin-w-(--bits-select-anchor-width)max-w-none- Attempted to remove any maximum width constraints, but this could lead to unbounded growth and didn't provide the precise control neededw-auto- Considered letting the browser automatically determine width, but this didn't resolve the fundamental constraint issuemax-w-min- The winning solution! This setsmax-width: min-content, which constrains the dropdown width while allowing content to wrap naturally when it exceeds the trigger widthCode Changes
The fix required a minimal, single-line addition to the Select.Content component:
// select-content.svelte class={cn( - "bg-popover text-popover-foreground ... min-w-[8rem] overflow-y-auto overflow-x-hidden ...", + "bg-popover text-popover-foreground ... min-w-[8rem] max-w-min overflow-y-auto overflow-x-hidden ...", className )}Minimal Reproduction Example
Benefits
Demo
Before the fix:
After the fix:
This fix ensures that shadcn-svelte's Select component maintains visual consistency between the trigger and dropdown, matching the quality and attention to detail users expect from the library.