Skip to content

Commit de3ab99

Browse files
committed
fix(popover): recalculate the content dimensions after the header has a height
1 parent ed80791 commit de3ab99

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/src/components/popover/popover.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ export class Popover implements ComponentInterface, PopoverInterface {
491491
inline
492492
);
493493

494+
this.recalculateContentOnHeaderReady();
495+
494496
if (!this.keyboardEvents) {
495497
this.configureKeyboardInteraction();
496498
}
@@ -540,6 +542,38 @@ export class Popover implements ComponentInterface, PopoverInterface {
540542
unlock();
541543
}
542544

545+
/**
546+
* Watch the header for height changes and trigger content dimension
547+
* recalculation when the header has a height > 0. This sets the offset-top
548+
* of the content to the height of the header correctly.
549+
*/
550+
private recalculateContentOnHeaderReady() {
551+
const popoverContent = this.el.shadowRoot?.querySelector('.popover-content');
552+
if (!popoverContent) {
553+
return;
554+
}
555+
556+
const contentContainer = this.usersElement || popoverContent;
557+
558+
const header = contentContainer.querySelector('ion-header') as HTMLElement | null;
559+
const contentElements = contentContainer.querySelectorAll('ion-content');
560+
561+
if (!header || contentElements.length === 0) {
562+
return;
563+
}
564+
565+
const ro = new ResizeObserver(async () => {
566+
if (header.offsetHeight > 0) {
567+
ro.disconnect();
568+
for (const contentEl of contentElements) {
569+
await contentEl.recalculateDimensions();
570+
}
571+
}
572+
});
573+
574+
ro.observe(header);
575+
}
576+
543577
/**
544578
* Dismiss the popover overlay after it has been presented.
545579
* This is a no-op if the overlay has not been presented yet. If you want

0 commit comments

Comments
 (0)