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.

Custom dropdown popperConfig={{ strategy: "fixed" }} works differently than expected.

See original GitHub issue

Prerequisites

Describe the bug

I want use popperConfig(strategy: “fixed” ) option in custom dropdown. but It works differently than expected in v2.1.1(bootstrap 5.1) The dropdown menu appears in the upper left corner of the screen.

스크린샷 2022-01-24 오후 12 21 09

Expected behavior

The dropdown menu appears in the under of the Custom Toggle(Anchor). v1.6.1(Bootstrap 4)

스크린샷 2022-01-24 오후 12 26 51

To Reproduce

  1. Go to react-bootstrap
  2. Dropdown
  3. Custom Dropdown Components Example
  4. add popperConfig={{ strategy: “fixed” }} in Dropdown.Menu

Reproducible Example

// The forwardRef is important!!
// Dropdown needs access to the DOM node in order to position the Menu
const CustomToggle = React.forwardRef(({ children, onClick }, ref) => (
  <a
    href=""
    ref={ref}
    onClick={(e) => {
      e.preventDefault();
      onClick(e);
    }}
  >
    {children}
    &#x25bc;
  </a>
));

// forwardRef again here!
// Dropdown needs access to the DOM of the Menu to measure it
const CustomMenu = React.forwardRef(
  ({ children, style, className, 'aria-labelledby': labeledBy }, ref) => {
    const [value, setValue] = useState('');

    return (
      <div
        ref={ref}
        style={style}
        className={className}
        aria-labelledby={labeledBy}
      >
        <FormControl
          autoFocus
          className="mx-3 my-2 w-auto"
          placeholder="Type to filter..."
          onChange={(e) => setValue(e.target.value)}
          value={value}
        />
        <ul className="list-unstyled">
          {React.Children.toArray(children).filter(
            (child) =>
              !value || child.props.children.toLowerCase().startsWith(value),
          )}
        </ul>
      </div>
    );
  },
);

render(
  <Dropdown>
    <Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components">
      Custom toggle
    </Dropdown.Toggle>

    <Dropdown.Menu as={CustomMenu} popperConfig={{ strategy: "fixed" }}>
      <Dropdown.Item eventKey="1">Red</Dropdown.Item>
      <Dropdown.Item eventKey="2">Blue</Dropdown.Item>
      <Dropdown.Item eventKey="3" active>
        Orange
      </Dropdown.Item>
      <Dropdown.Item eventKey="1">Red-Orange</Dropdown.Item>
    </Dropdown.Menu>
  </Dropdown>,
);

Screenshots

No response

What operating system(s) are you seeing the problem on?

macOS

What browser(s) are you seeing the problem on?

Chrome

What version of React-Bootstrap are you using?

2.1.1

What version of Bootstrap are you using?

5.1.3

Additional context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kyletsangcommented, Feb 7, 2022

The initial rendered position is wrong, but once you scroll, it corrects itself.

As a workaround try adding renderOnMount to the dropdown menu.

1reaction
Doutencommented, Oct 25, 2022

RenderOnMount was causing weird issues for me. Since it fixes itself when scrolling I did this instead.

  const popperConfig = {
    strategy: "fixed",
    onFirstUpdate: () => window.dispatchEvent(new CustomEvent('scroll')),
  }

https://popper.js.org/docs/v2/lifecycle/#hook-into-the-lifecycle

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dropdown Bootstrap 4 doesn't work in production of angular's ...
The problem is with bootstrap 4.4+ version, change to bootstrap 4.3.1 and will works fine. You can install it from npm and then...
Read more >
React Bootstrap Fixed Dropdown Popper - CodeSandbox
React Bootstrap Fixed Dropdown Popper. https://stackoverflow.com/questions/63631542/react-bootstrap-dropup-menu-partially-visible-in-the-datagrid.
Read more >
Bootstrap dropdowns - CoreUI
Bootstrap dropdown component allows you to toggle contextual overlays for displaying lists, links, and more html elements.
Read more >
Dropdowns · Bootstrap v5.1
Here's how you can put them to work with either <button> elements: Dropdown ... Opt into darker dropdowns to match a dark navbar...
Read more >
Falcon Sandbox v8.30 © Hybrid Analysis
https://cardportal.works.com/gar/. This report is generated from a file or URL submitted to this webservice on July 3rd 2019 06:58:31 (UTC) and action ...
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