2

I use a primeng dropdown input and I want to make the div that holds the label placeholder to have 100% width.
Here is how I use it:

<div class="ui-grid ui-grid-responsive ui-fluid">
    <div class="ui-grid-row">
        <div class="ui-grid-col-2">
            <p-dropdown [options]="solutionsDropDownData" [(ngModel)]="solutionDropDownValue" placeholder="Solution..."
                [filter]="true" (onChange)="onSolutionChange($event)">
            </p-dropdown>
        </div>
    </div>
</div>

The problem is that I get a space after the placeholder while I want the placeholder to be full width. The space can be seen below:
white space width after placeholder 1

When I choose an other value, with smaller length for example, the width of the space changes, it becomes bigger if I used the same example.
white space width after placeholder 2

I already tried this approaches, but none of them worked:

  1. used autoWidth parameter, but this one gives me Can't bind to 'autoWidth' since it isn't a known property of 'p-dropdown'. error if I use it with brackets; the error disappears if I use it without brackets, but it doesn't work (I mention that I imported the DropdownModule);

  2. used css classes like below (I used them separately and both, alternatively):

    .ui-dropdown-label-container{ width:100% !important; }

    .ui-dropdown .ui-dropdown-panel { min-width: 100% !important; width: max-content; }

  3. used style parameter.

GabrielAV
  • 31
  • 5

2 Answers2

0

It happens because of the stylesheet you using for PrimeNG. We experienced same visual problem and achieved that by adding below css class to styles.css

.ui-dropdown .ui-dropdown-label-container {
    width: inherit !important;
}

Actually inherit calls for 100%, I couldn't understand why it didn't work for you.

Berkin Sansal
  • 402
  • 1
  • 3
  • 9
0

I managed to solve this by adding the code below:
enter image description here

enter image description here


Basically, I just added the dropdown inside a div and changed the background color of the div that's containing it.

GabrielAV
  • 31
  • 5