Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng-select inside dialog add extra hidden height

Tags:

angular

when using ng-select inside a dialog, the content of the dropdown is not displayed outside the dialog with an overflow. I saw this question also on github, but there was no solution found.

https://github.com/ng-select/ng-select/issues/240

Demo: https://stackblitz.com/edit/angular-material2-issue-yesgfz

How can I solve this?

Expected behaviour:

enter image description here

Actual behaviour:

enter image description here

Solution from github with [appendTo]="'body'"

enter image description here

like image 972
Dev Db Avatar asked May 16 '18 08:05

Dev Db


2 Answers

paste appendTo="body" on your ng-select tag

<ng-select appendTo="body" [items]="data" bindLabel="name" bindValue="id" placeholder=""></ng-select>

like image 69
vijay kanaujia Avatar answered Sep 30 '22 20:09

vijay kanaujia


You could, even if it's probably not ideal, do this

<div style="display: block; height: 40px;">
  <ng-select [searchable]="false" style="position: absolute; width: 200px;">
    <ng-option *ngFor="let option of options" [value]="option">
      {{ option }}
    </ng-option>
  </ng-select>
</div>

Requires some fixed values, but the absolute position solves your issue and fiddling a bit with css may give you the result you want in a decent way.

Edit: Stackblitz link

like image 44
Fussel Avatar answered Sep 30 '22 21:09

Fussel