Fix long option not truncated issue in dropdown - #19584
Open
ayush1298 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent p-select and p-multiselect overlays from expanding beyond the trigger width when option text is very long, by introducing an overlay max-width constraint and adding truncation styles.
Changes:
- Added
autoMaxWidthtoOverlayOptionsand appliedmax-widthduring overlay alignment when enabled. - Exposed a new
autoWidthinput on Select and MultiSelect that forwards configuration to the overlay. - Added default truncation (ellipsis) styles to Select/MultiSelect label/option-related CSS.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/primeng/src/select/style/selectstyle.ts | Adds truncation styles for Select label/option text. |
| packages/primeng/src/select/select.ts | Forwards new overlay sizing option and introduces autoWidth input. |
| packages/primeng/src/overlay/overlay.ts | Applies maxWidth constraint based on the target width when enabled. |
| packages/primeng/src/multiselect/style/multiselectstyle.ts | Adds truncation styles; modifies invalid placeholder selector coverage. |
| packages/primeng/src/multiselect/multiselect.ts | Forwards new overlay sizing option and introduces autoWidth input. |
| packages/primeng/src/api/overlayoptions.ts | Adds new autoMaxWidth option to the overlay options interface. |
Comments suppressed due to low confidence (2)
packages/primeng/src/select/select.ts:687
- The new
autoWidthinput introduces new overlay sizing behavior, but there are no unit tests covering it (e.g. verifying whether the overlay element gets/doesn't get amax-widthmatching the target whenautoWidthis toggled). Since this component has an existing spec suite, adding a focused test would help prevent regressions.
@Input({ transform: booleanAttribute }) autofocusFilter: boolean = true;
/**
* Whether the width of the overlay mirrors the width of the component.
* @group Props
*/
@Input({ transform: booleanAttribute }) autoWidth: boolean = true;
packages/primeng/src/multiselect/multiselect.ts:747
- The new
autoWidthinput introduces new overlay sizing behavior, but there are no unit tests covering it (e.g. verifying whether the overlay element gets/doesn't get amax-widthmatching the target whenautoWidthis toggled). Since this component has an existing spec suite, adding a focused test would help prevent regressions.
@Input({ transform: booleanAttribute }) autofocusFilter: boolean = false;
/**
* Whether the width of the overlay mirrors the width of the component.
* @group Props
*/
@Input({ transform: booleanAttribute }) autoWidth: boolean = true;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fixes #19427
The Issue:
Dropdown overlays for p-select and p-multiselect only had a min-width set (to match the input box) but no max-width. When options contained long text, the overlay expanded beyond the input box width instead of staying aligned and truncating the content.
The Fix:
Overlay constraint: Added an autoMaxWidth property to OverlayOptions and updated the Overlay layout alignment logic to apply maxWidth matching the target's width when enabled.
Component config: Exposed
autoWidth(default true) on Select and MultiSelect components, which forwardsautoMaxWidth: !autoWidthto the underlying overlay.Ellipsis styles: Added default CSS truncation styles (text-overflow: ellipsis, overflow: hidden, white-space: nowrap) to option/label classes in both components to handle constrained widths cleanly.
Video with fix is here: