Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuPortal placement is off for position='fixed' if a parent has transform: scale #5846

Open
kbrooks opened this issue Jan 11, 2024 · 0 comments
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet

Comments

@kbrooks
Copy link

kbrooks commented Jan 11, 2024

Bug description

For a menu inside a scaled div, the top and left properties on MenuPortal styles are calculated based on the viewport instead of based on the "containing block", which is the scaled div.

Fixed positioning is similar to absolute positioning, with the exception that the element's containing block is the initial containing block established by the viewport, unless any ancestor has transform, perspective, or filter property set to something other than none (see CSS Transforms Spec), which then causes that ancestor to take the place of the elements containing block.
https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed_positioning

This causes the menuportal to be displayed to the bottom-right of where it should be:
Screenshot 2024-01-11 at 12 09 10 PM

The issue is simple to reproduce by placing a ReactSelect component inside of a div with a transform: scale style.

import React from "react";
import ReactDOM from "react-dom";

import ReactSelect from "react-select";

function Selection() {
  return (
    <ReactSelect
      menuPosition="fixed"
      options={[
        {
          label: "hi",
          value: "hi",
        },
        {
          label: "bye",
          value: "bye",
        },
      ]}
    />
  );
}

function FixedBox({ children }: { children: React.ReactNode }) {
  return (
    <div
      style={{
        margin: 100,
        border: "1px solid black",
        transform: "scale(1)",
      }}
    >
      <h1>fixed container</h1>
      {children}
    </div>
  );
}

function Example() {
  return (
    <FixedBox>
      <Selection />
    </FixedBox>
  );
}

ReactDOM.render(<Example />, document.getElementById("root"));

sandbox link

@kbrooks kbrooks added the issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet
Projects
None yet
Development

No branches or pull requests

1 participant