ui5-responsivePopover: when open the ui5-responsivePopover, it moves from other place to the target openBy element place.
Hi colleague, i am from Successfactors team.Please help to take a look at this issue.
Describe the bug When open the ui5-responsivePopover, the popover showing at other place at first, then move to the target openBy element place. Expected: it should be located at the openBy element place directly when first showing.
To reproduce Steps to reproduce the behavior:
- Create one responsivePopover and openBy button, click on button to open the responsivePopover
- Only render responsivePopover when isResponsivePopoverOpen=true
const [isResponsivePopoverOpen, setResponsivePopoverOpen] = useState(false);
const handleButtonClick = () => {
setResponsivePopoverOpen(true);
resPopoverRef.open(buttonRef)
};
return (
<ui5-button ref={buttonRef} onClick={handleButtonClick}>Open Popover</ui5-button>
{isResponsivePopover && (
<ui5-responsive-popover ref={resPopoverRef} header-text="Newsletter subscription">
<div class="popover-content">
<ui5-label for="emailInput" required>Email: </ui5-label>
</div>
</ui5-responsive-popover>
)}
)
Expected behavior ui5-responsivePopover should be located at the openBy element place directly when first showing.
Screenshots

@SherrySherry123
Hi, thanks for reporting, can you provide a URL to your app top look at and debug the issue or isolated example.
Best regards, ilhan
Hi @ilhan007 ,
Please refer to the url. https://github.wdf.sap.corp/pages/xweb/goalmanagementx/?path=/story/goal-components-goalpageheadertitle--default
Regards, Sherry
Hi @SherrySherry123,
I was not able to reproduce the issue on my side.
As much as I can see you are using version RC7. Could you try to update the version of ui5-webcomponents to 0.21.x.
Best regards, Filip
Hi @fifoosid , I have tried with the latest version 0.21.0, but the issue still exists.
I find a workaround to set a fixed width for the responsivePopover to avoid the width calculation, so you can not reproduce it in the provided github page now;
But if remove the fixed width ,the issue will show again. we still hope that you can help to fix it.

Regards, Sherry
Hi @fifoosid ,
Here is the example https://codesandbox.io/s/quirky-driscoll-g6seb?file=/src/App.js.

Regards, Sherry
Hello @SherrySherry123,
I managed to debug what the issue is in the isolated example. Turns out that the problem comes from the way you instantiate the popover. Currently you have the following code:
<ui5-responsive-popover
header-text="Newsletter subscription"
placement-type="Bottom"
ref={resPopoverRef}
onBeforeClose={handleResponsivePopoverBeforeClose}
>
{isOpen && (
<div>
<ui5-label>
Note: If you open the page in mobile, dialog would be displayed.
</ui5-label>
</div>
)}
</ui5-responsive-popover>
The problem is coming from the way the default slot is passed to the ui5-responsive-popover and the way React updates the DOM. What happens is that when you open the popover, it is rendered once, and then React inserts the div as default slot(it is inserted later because of the condition), which changes the width of the popover. In order to resolve the issue, change your code to the following:
<ui5-responsive-popover
header-text="Newsletter subscription"
placement-type="Bottom"
ref={resPopoverRef}
onBeforeClose={handleResponsivePopoverBeforeClose}
>
<div>
<ui5-label>
Note: If you open the page in mobile, dialog would be displayed.
</ui5-label>
</div>
</ui5-responsive-popover>
Hi @fifoosid Thanks for your kindly response. But i still need your help, i know the issue can not reproduce with your provided solution. But from the performance optimization perspective, i hope the popover content only be initialized after the popover opened; Here is my use case, let's imagine there is a large list in the popover, it will cause large performance consumption to render the list even thought the popover never be opened.
So how to deal with this case to lazy load the large list and only render it after popover opened to reduce the performance consumption.
Regards, Sherry
Hi @SherrySherry123
I think that your comment is with regards to the following issue: #1750
If so, my advice is to sync the lazy loading & the opening of the responsive popover. What I mean is to call responsivePopover.open() later in time(this time would be used by React to insert the content of the responsive popover in the DOM).
I would personally go for ~17ms timeout because requestAnimationFrame is called on every 1000/60 (explained below), or around 16.7 milliseconds. The reason for that is simple: the requestAnimationFrame that you would have waited to be executed, would insert the content in the DOM. In other words, you can wait for 17ms before opening the popover:
setTimeout(() => { document.querySelector("ui5-responsive-popover").open(); }, 17) Explanation: The numbers are not random: As you can read here, this value simulates how often the real requestAnimationFrame() will typically be called by the browser.
Thanks @fifoosid for the quick response and kindly explanation, the proposed solution works for me.
Regards, Sherry