Skip to content

Fix: Recalculate popover position on lazy content #1129

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

madsrasmussen
Copy link
Contributor

@madsrasmussen madsrasmussen commented Jun 24, 2025

This pull request introduces enhancements to the UUIPopoverContainerElement class in packages/uui-popover-container/lib/uui-popover-container.element.ts. The changes focus on improving responsiveness and handling size changes dynamically by adding a ResizeObserver.

Adds a slotchange event handler to the slot in UUIPopoverContainerElement. This ensures the popover updates when its slotted content changes by calling #initUpdate within a requestAnimationFrame.
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 12:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances UUIPopoverContainerElement by recalculating its position whenever the slot content changes, ensuring the popover stays correctly positioned with lazy-loaded or dynamic content.

  • Introduces a private #onSlotChange method that uses requestAnimationFrame to trigger #initUpdate.
  • Updates the render method to attach the @slotchange event listener to the <slot> element.
Comments suppressed due to low confidence (2)

packages/uui-popover-container/lib/uui-popover-container.element.ts:354

  • [nitpick] Consider adding a brief JSDoc comment above #onSlotChange to explain its role in triggering reposition logic when slot content changes.
  #onSlotChange() {

packages/uui-popover-container/lib/uui-popover-container.element.ts:361

  • There aren’t any tests covering the slotchange handler; consider adding a unit or integration test that simulates slot content updates and verifies #initUpdate is called.
    return html`<slot @slotchange=${this.#onSlotChange}></slot>`;

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1129.westeurope.azurestaticapps.net

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1129.westeurope.azurestaticapps.net

@madsrasmussen madsrasmussen marked this pull request as ready for review June 25, 2025 11:14
@madsrasmussen madsrasmussen changed the title Fix: Reposition popover on lazy content Fix: Recalculate popover position on lazy content Jun 25, 2025
Copy link

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1129.westeurope.azurestaticapps.net

protected override firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);

this.#sizeObserver = new ResizeObserver(entries => {
Copy link
Member

Choose a reason for hiding this comment

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

Does firstUpdated gets triggerede again when a component has been shortly out of the DOM?

I'm thinking that the sizeObserver gets disconnected on disconnectedCallback, and then I would be afraid that it never sets up the sizeObserver again.

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