Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: popover right side arrow placement #17477

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mschn
Copy link

@mschn mschn commented Jan 23, 2025

Defect Fixes

#16406

Fix an issue with the popover arrow placement.
The issue can be reproduced on the showcase here when using a small viewport width:
https://primeng.org/popover#basic

Current issue

image

With this PR

image

Copy link

vercel bot commented Jan 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Updated (UTC)
primeng ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 1:07pm
primeng-v18 ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 1:07pm

Copy link

vercel bot commented Jan 23, 2025

@mathieu-schnoor is attempting to deploy a commit to the primetek Team on Vercel.

A member of the Team first needs to authorize it.

@mschn mschn force-pushed the fix-popover-arrow-right branch 2 times, most recently from efcf680 to e1b6290 Compare January 23, 2025 22:20
}
this.container?.style.setProperty('--overlayArrowLeft', `${arrowLeft}px`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this line correct and should be reinstated? --overlayArrowLeft always is defined. if (containerOffset.left >= targetOffset.left) then the property is set to 0px. Your proposed change would have the property undefined. Maybe your change has no negative impact, have you tested your change for this case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like --overlayArrowLeft is not used anymore in the code base, and that's the initial source of the bug.

With v18 and the introduction of the new theming system, --overlayArrowLeft was removed from the CSS file and we're using --p-popover-arrow-offset from the design tokens instead.

--p-popover-arrow-offset has a default value from the theme so if we don't override it here it will not be undefined

@@ -330,13 +328,12 @@ export class Popover extends BaseComponent implements AfterContentInit, OnDestro

const containerOffset = <any>getOffset(this.container);
const targetOffset = <any>getOffset(this.target);
const borderRadius = this.document.defaultView?.getComputedStyle(this.container!).getPropertyValue('border-radius');
let arrowLeft = 0;
const targetWidth = getWidth(this.target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For efficiency, move this line after line 333

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width calculation can be removed as you suggested
the arrow is not centered on the target element by default so there's no reason it should be in that case


if (containerOffset.left < targetOffset.left) {
arrowLeft = targetOffset.left - containerOffset.left - parseFloat(borderRadius!) * 2;
const arrowLeft = targetOffset.left - containerOffset.left + targetWidth / 2;
this.container?.style.setProperty('--p-popover-arrow-offset', `${arrowLeft}px`);
Copy link
Contributor

@rosenthalj rosenthalj Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you even need to center the arrow?

why not replace
arrowLeft = targetOffset.left - containerOffset.left + targetWidth / 2
with
arrowLeft = targetOffset.left - containerOffset.left

This should look good and targetWidth would not have to be calculated?

Copy link
Author

@mschn mschn Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centering the arrow is not consistent with the default behavior, you are right i will remove it.

if we simply use targetOffset.left - containerOffset.left it looks like this:
image

so it's still missing some offset here
I think the best is to reapply the --p-popover-arrow-offset value that comes from the theme,
that way it will be consistent with the default scenario:

image

@mschn mschn force-pushed the fix-popover-arrow-right branch from e1b6290 to 411a274 Compare January 24, 2025 13:07
@mschn mschn requested a review from rosenthalj January 24, 2025 13:07
Copy link
Contributor

@rosenthalj rosenthalj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I like the results of your PR, but I would be worried about recomputing/changing the PrimeNG property --p-popover-arrow-offset.

@mschn
Copy link
Author

mschn commented Jan 24, 2025

maybe I misunderstand, but what does --overlayArrowLeft do ?
it looks like it's an old property from v17 that should have been cleanup in v18 ?

image

changing the value of this property does not move the arrow which is the cause of the bug.

@rosenthalj
Copy link
Contributor

rosenthalj commented Jan 24, 2025

Examining the v19 demo, it looks like --overlayArrowLeft is used incorrectly and is probably a v17 barnacle (as you have deduced). See annotated screenshot listed below.

As a result, I think that your current approach is a viable solution. I do not have an alternative approach.
PLEASE SEE NEXT COMMENT

Angular_Popover_Component

@rosenthalj
Copy link
Contributor

The Screenshot listed below shows the v17 working properly and the "inspected" page. As a result, I believe the correct fix is not to change the popover.ts file but to update the popoverstyle.ts (CSS file) similar to v17

Angular_OverlayPanel_Component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants