I'm using primeng p-dropdown module. I've attached an <ng-template>
to show my data in three columns, name, address, and email respectively. Without using appendTo
attribute leads to a lot of text dropping to the next row and an ugly horizontal scrollbar. I used appendTo="body"
and the text dropping issue is partially fixed, but I still see the address column text dropping to the next line.
Upon further investigation, I found out that the p-dropdown
outputs an overlay div
element and it has an inline css style attribute of 'min-width'
set to '473px'
in my case.
Here's the div element that gets outputted.
<div class="ng-trigger ng-trigger-overlayAnimation ng-tns-c5-5 extendWidth ui-dropdown-panel ui-widget ui-widget-content ui-corner-all ui-shadow ng-star-inserted" ng-reflect-klass="extendWidth" ng-reflect-ng-class="ui-dropdown-panel ui-widget u" style="min-width: 473px; z-index: 1001; top: 210px; left: 419.875px; transform: translateY(0px); opacity: 1;">
I used chrome developer tools to change it to 635px
and the overlay panel gets wide enough to show the address in one line, the horizontal scrollbar is not there anymore.
Now, I'm trying to override this inline style from Angular and I'm unable to do so.
- The library documentation provides
panelStyle
property to apply an inline style on the overlay div element, I've tried using it but since!important
cannot be applied used here (because it sends these inline styles tongStyle
on the backend). So, it was useless in my case. - Then I tried using
panelStyleClass
attribute to set the class toextendWidth
. The class name appears on the div but like thisng-reflect-klass="extendWidth"
. And the css styles present inside the class won't apply even with:host >>>
<p-dropdown
name="customer"
[style]="{ width: '100%' }"
(onChange)="addCustomer()"
[autoDisplayFirst]="false"
[options]="customers"
[(ngModel)]="selectedCustomer"
optionLabel="fullName"
[filter]="true"
autofocus="true"
[showClear]="true"
required
appendTo="body"
panelStyleClass="extendWidth"
>
<ng-template let-customer pTemplate="item">
<div class="p-grid">
<div class="p-col-3">{{ customer.value.fullName }}</div>
<div class="p-col-6">{{ customer.value.streetAddress }}</div>
<div class="p-col-3">{{ customer.value.email }}</div>
</div>
</ng-template>
</p-dropdown>
It should let me override the custom min-width attribute in some way.