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): dynamic width popover is positioned correctly #28072

Merged
merged 8 commits into from
Aug 31, 2023
Merged

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Aug 29, 2023

Issue number: resolves #27190, resolves #24780


What is the current behavior?

Popovers with dynamic widths were not being positioned correctly relative to the trigger element. This was happening because the child component always had dimensions of 0 x 0. Ionic has logic built-in to wait for the child components to be rendered, but this was not working as intended for two reasons:

  1. this.usersElement was referencing the popover element itself not the user’s component. When calling deepReady on
    await deepReady(this.usersElement);
    we are waiting for the popover to be hydrated, not the child content. The popover was already hydrated on page load, so this resolves immediately. However, the child content that was just added to the DOM has not yet been hydrated, so we aren’t waiting long enough.

This is happening because we return BaseComponent from attachComponent which is a reference to the overlay:

Other framework delegates return the actual child content:

  1. attachComponent is unable to return the correct element currently because the child content has not been mounted yet in this scenario. ionMount is emitted after attachComponent resolves:

What is the new behavior?

  • ionMount is emitted before attachComponent runs
  • attachComponent now consistently returns the child view if present in the DOM
  • Added a test

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.3.2-dev.11693321763.15a54694

@stackblitz
Copy link

stackblitz bot commented Aug 29, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label Aug 29, 2023

this.ionMount.emit();

this.usersElement = await attachComponent(delegate, el, this.component, ['ion-page'], this.componentProps, inline);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving ionMount above attachComponent isn't strictly necessary for modal, but I decided to make the change so we are at least consistent with ion-popover.

@liamdebeasi liamdebeasi changed the title Fw 4046 fix(popover): dynamic width popover is positioned correctly Aug 29, 2023
@liamdebeasi liamdebeasi marked this pull request as ready for review August 29, 2023 15:49
@liamdebeasi liamdebeasi requested review from a team and thetaPC and removed request for a team August 29, 2023 15:49
Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

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

LGTM, with minor suggestion.

@@ -449,6 +449,9 @@ export class Popover implements ComponentInterface, PopoverInterface {
const { el } = this;

const { inline, delegate } = this.getDelegate(true);

this.ionMount.emit();
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be beneficial to add a comment to why it's important to have ionMount above attachComponent to prevent it being moved to a lower position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Added in c4beade.

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
4 participants