question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autosize ng-select width to longest option width

See original GitHub issue

Is your feature request related to a problem? Please describe. Default <select> behavior is to size itself to the width of the longest option it contains. This allows for the select to stay fixed width throughout the process of selecting options and prevents “content jumping” in inline forms.

Describe the solution you’d like Mimic regular select behavior. Currently, you can only set width by css, but you don’t know the width of largest possible option during runtime and there’s apparently no way to calculate that, as options are not in DOM, until clicked.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
varnastadeuscommented, Dec 4, 2018

I don’t think this is good practice, usually your control is based on parents width or static width you define. Width based on longest option will result in miss-aligned UI and problems with overflowing content. I think this feature will add unnecessary complexity and extra calculations and the benefit won’t outweigh the cost.

15reactions
varnastadeuscommented, Aug 5, 2019

here is simple working scss solution

<ng-select class="auto-grow"></ng-select>
.ng-select.auto-grow {
  display: flex;

  .ng-select-container {
    min-width: 100px;
    width: auto;
  }

  .ng-dropdown-panel {
    width: auto;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

make ng-select width adjust to selected items / available ...
I'd like it to be sized such that the width is at least the maximum width the component would have if any one...
Read more >
How to Expand Select Box to its Default Width on Focus ...
Answer: Use the CSS :focus pseudo-class. By default the size of the <select> element is depend on the size of the largest <option>...
Read more >
ng-select fixed width
ng-select -container width. Default <select> behavior is to size itself to the width of the longest option it contains. This allows for the...
Read more >
ngSelect Customizations: Draggable Panel
Today I'm writing about how I made the ng-select dropdown resize by ... panel width, panel height, dragging boolean, and X/Y coordinates.
Read more >
Material2 Select Width Issues
font-size: 8pt;. float: right;. } .alt { .mat-form-field {. width: auto !important;. } .mat-select-value {. max-width: 100%;. width: auto;. }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found