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.

[Question] Support for :top-layer content, e.g. <dialog> and [popup]

See original GitHub issue

Content in a <dialog> that is opened with showModal() or showPopUp() via the popup attribute will not actually have “offsetParents” or “clippingAncestors”. How do you think it is best for the library to support positioning that content?

Particularly, if a reference element and a floating element are both bound in an element with a matrix transform, a la https://codesandbox.io/s/floating-ui-dom-template-forked-es3dfl?file=/src/index.js, do you foresee adding extra checks for this reality, or surfacing a flag so a use can opt-out of ancestor math or something else.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Westbrookcommented, Sep 22, 2022

I’m testing out this fairly naive middleware, based on the offset middleware, to manage this context:

import { Middleware, MiddlewareArguments } from "@floating-ui/dom";

export const topLayer = (): Middleware => ({
  name: 'topLayer',
  async fn(middlewareArguments: MiddlewareArguments) {
    const { x, y, elements: { reference, floating } } = middlewareArguments;
    let onTopLayer = false;
    const diffCoords = {
        x: 0,
        y: 0,
    }
    // browsers will throw when they do not support the following selectors, catch the errors.
    try {
        onTopLayer = onTopLayer || floating.matches(':open');
    // eslint-disable-next-line no-empty
    } catch (e) {}
    try {
        onTopLayer = onTopLayer || floating.matches(':modal');
    // eslint-disable-next-line no-empty
    } catch (e) {}

    if (onTopLayer) {
        // :top-layer content will be positioned from `window` get the reference's position from there, too.
        const rect = reference.getBoundingClientRect()
        diffCoords.x = rect.x;
        diffCoords.y = rect.y;
    }

    return {
      x: x + diffCoords.x,
      y: y + diffCoords.y,
      data: diffCoords,
    };
  },
});

This feels like a situation that will come up more and more as these specs solidify and expect. It feels like this should be core library functionality, or at least a core library middleware.

0reactions
Westbrookcommented, Oct 30, 2022

Can do! My team and I are specifically looking into all of this right now, so hopefully I can get your something this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Meet the top layer: a solution to z-index:10000
The top layer helps solve the problem of rendering content above the ... With new built-in components and APIs like <dialog> and "Pop-up", ......
Read more >
Popover API (Explainer) - Open UI
The top layer is a layer that paints on top of all other page content, with the exception of other elements currently in...
Read more >
WPF MVVM dialog example - Stack Overflow
I have a standard dialog window, with a content control in it. When ShowDialog is called it creates a new standard dialog, adds...
Read more >
Dialog / Popup boxes not displaying content fully?
I have a problem with pop up dialog boxes on Windows 10 not displaying the content fully. Its rather frustrating as I can...
Read more >
HTMLDialogElement.showModal() - Web APIs - MDN Web Docs
It displays into the top layer, along with a ::backdrop pseudo-element. Interaction outside the dialog is blocked and the content outside it ...
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