ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

ui5-responsivePopover: when open the ui5-responsivePopover, it moves from other place to the target openBy element place.

Open SherrySherry123 opened this issue 6 years ago • 10 comments

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:

  1. Create one responsivePopover and openBy button, click on button to open the responsivePopover
  2. 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 responsivePopover issue

SherrySherry123 avatar Jun 09 '20 03:06 SherrySherry123

@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

ilhan007 avatar Jun 09 '20 04:06 ilhan007

Hi @ilhan007 ,

Please refer to the url. https://github.wdf.sap.corp/pages/xweb/goalmanagementx/?path=/story/goal-components-goalpageheadertitle--default

Regards, Sherry

SherrySherry123 avatar Jun 09 '20 09:06 SherrySherry123

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

fifoosid avatar Jun 12 '20 11:06 fifoosid

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. responsivePopover with fixed width

Regards, Sherry

SherrySherry123 avatar Jun 15 '20 06:06 SherrySherry123

Hi @SherrySherry123

Could you provide an isolated example of the issue via CodeSandbox

fifoosid avatar Jun 15 '20 12:06 fifoosid

Hi @fifoosid ,

Here is the example https://codesandbox.io/s/quirky-driscoll-g6seb?file=/src/App.js. sandbox

Regards, Sherry

SherrySherry123 avatar Jun 16 '20 09:06 SherrySherry123

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>

fifoosid avatar Jun 17 '20 08:06 fifoosid

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

SherrySherry123 avatar Jun 19 '20 02:06 SherrySherry123

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.

SherrySherry123 avatar Jun 19 '20 02:06 SherrySherry123

Thanks @fifoosid for the quick response and kindly explanation, the proposed solution works for me.

Regards, Sherry

SherrySherry123 avatar Jun 19 '20 02:06 SherrySherry123