Popup-Menu doesn't work in positioned divs
Hi,
I try currently to migrate to the newest version of primeng but I run into problems in the popup-menu.
Normally, the popup-menu runs excellently, but If you put it into a div that is positioned the absolute positioning of the element fails because it's always positioned to the top of the page and not of its correct parent.
If you look into the old version (before the refactoring of the menu), the menus were created on root-level in the dom-tree and the positioning worked. But now, the menu is created at the place where the tag is written and so the computation of the offset isn't correct anymore.
Example to reproduce:
DOES WORK:
<button type="button" pButton icon="fa fa-list" label="Show" (click)="menu3.toggle($event)"></button>
<p-menu #menu3 popup="popup" [model]="menuItems"></p-menu>
DOESN'T WORK:
<div style="position: relative; border: 1px dashed green;">
<button type="button" pButton icon="fa fa-list" label="Show" (click)="menu.toggle($event)"></button>
<p-menu #menu popup="popup" [model]="menuItems"></p-menu>
</div>
Any clue how to solve this problem?
Regards, Peter
Hi , Thats because of our menu contains position:absolute when you wrap it with another positioned div it still works but menu is visible somewhere else on the screen how is your usecase ?
This is expected as menu is absolute positioned against document but having a div with relative positioning makes it relative to this div not the body causing an offset.
One solution could be adding an option like appendToBody="true", we'll try to see if this breaks anything inside the context of Angular2.
Can you avoid position:relative by the way?
Hi,
thanks for the fast answer.
Unfortunately, we have to create a dashboard and the library that we are using needs to position the divs by css.
At the moment, we are stick on beta.5 because in that version, the popup-position is working correct.
Regards, Peter
https://github.com/primefaces/primeng/issues/639 i think this solution will work for you.
appendTo="body" should do it.
cool man, it is working
For me, appendTo="body" also working but still not showing items! I need to mention that I'm using serenity primeng template
we are having he same problem in React. though in react i cannot use the appendTo="body"
appendTo="body" is not working . Any other solutions?
append to body ruins the tab accessibility and makes it untargetable,
appendTo="body" is not working . Any other solutions?
Try to use this -> [appendTo]=id it will work in all cases.
#id means try to pass id in ng-templates, div or ng-container
- for example -
<ng-template #id></ng-template><ng-container #id></ng-container><div #id></div>