question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Popover is behind element even with FloatingPortal

See original GitHub issue

I am trying to use a FloatingPortal to take the floating elements outside the flow of the document.

However, I am still seeing odd behaviour when the popover should be on top of an element.

image

Current code:

MyPopover.js

const { x, y, reference, floating, strategy } = useFloating({
    placement: "bottom-start",
    middleware: [flip(), shift(), offset(5)],
 })

...
<>
    <Popover.Button 
       ref={reference} 
       className={contentContainerStyle} 
     />
    <Popover.Panel
      static
      ref={floating}
      style={{
        position: strategy,
        top: y ?? "",
        left: x ?? "",
      }}
    >
    ...
    </Popover.Panel>
</>

App.js

const AppWithStore = () => {
  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <FloatingPortal>
          <App />
        </FloatingPortal>
      </PersistGate>
    </Provider>
  )
}

What am I missing to take the floating UI out of the flow of the document?

Versions: “@floating-ui/react-dom”: “^0.6.3”, “@floating-ui/react-dom-interactions”: “^0.3.1”,

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
atomikscommented, Apr 22, 2022

The FloatingPortal should only wrap the floating element, not the whole app. Further, you may need to set a z-index on the floating element if there are other positioned elements that can obscure it. isolation: isolate on the root app (not the floating portal node) may also help (cc: @FezVrasta still have no idea how that works lol)

0reactions
wmoneckecommented, Apr 22, 2022

The code in the docs was not working for me for some reason.

 useEffect(() => {
    if (!refs.reference.current || !refs.floating.current) {
      return;
    }
 
    // Only call this when the floating element is rendered
    return autoUpdate(
      refs.reference.current,
      refs.floating.current,
      update
    );
  }, [refs.reference, refs.floating, update]);

This is the only hack / code that managed to get it working:

 const isMountedRef = useRef(false)
  const { x, y, reference, floating, strategy, update, refs } = useFloating({
    placement: "bottom-center",
    middleware: [flip(), shift(), offset(5)],
  })


  useEffect(() => {
    if (isMountedRef.current) {
      return debounce(update, 100)
    }
    isMountedRef.current = true
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap 3 Popover gets hidden behind the element which ...
I usually add(or toggle) a CSS to an element I want to control instead of adding CSS attributes to it. So instead of:....
Read more >
Tutorial | Floating UI
Create a new HTML document with two elements, a <button> and a tooltip <div> : ... apply a tooltip or popover to an...
Read more >
Popover has wrong z-index and gets hidden behind the nav bar
The popup button is on the navbar, but the message gets hidden underneath. I checked it with Firebug and it seems navbar has...
Read more >
Popovers - Bootstrap
Documentation and examples for adding Bootstrap popovers, like those found in iOS, to any element on your site.
Read more >
Popover | Components - BootstrapVue
The Popover feature provides a tooltip-like behavior, can be easily applied to any interactive element via the component or v-b-popover directive.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found