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.

[Listbox] ListboxPopover portal immediately closes first time it's opened within a Dialog. ( React 17+)

See original GitHub issue

🐛 Bug report

Current Behavior

  1. With a Listbox visible in a Dialog, click the Listbox
  2. Listbox opens and closes immediatly.
  3. Click again.
  4. Listbox opens normally.

This seems to be fine in older versions of React, not working in 17.0.1

Expected behavior

  1. With a Listbox visible in a Dialog, click the Listbox
  2. Listbox opens normally.

Reproducible example

CodeSandbox Template

You can replicate this by using the buttons in the dialog toggling the portal to true. It should be fine with portal set to false.

Suggested solution(s)

Additional context

Unit test:

     it(`should display ListboxPopover`, () => {
        let { getByRole, queryByRole } = render(
          <Dialog isOpen={true} aria-label="test">
          <Listbox portal={true}>
            <ListboxOption value="pollo">Pollo</ListboxOption>
            <ListboxOption value="asada">Carne Asada</ListboxOption>
            <ListboxOption value="lengua">Lengua</ListboxOption>
            <ListboxOption value="pastor">Pastor</ListboxOption>
          </Listbox>
          </Dialog>
        );

        act(() => void fireMouseClick(getByRole("button")));
        expect(queryByRole("listbox", { hidden: false })).toBeTruthy();
      });

This test will fail. Changing portal toportal={false} will pass.

Your environment

Software Name(s) Version
Reach Package @reach/listbox 0.11.2-0.13.0
React 17.0.1
Browser Chrome
Assistive tech
Node
npm/yarn
Operating System MacOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chaancecommented, Apr 8, 2021

I’m also afraid there’s another bug in your example: all options except for Popeye’s are invalid and should not be selectable. We’ll make sure to tackle that in the next release too 🥇

1reaction
loquecommented, Jan 29, 2021

@einaralex no need! Although I meant to add information for further exploration, I really don’t know the possible consequences of doing that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listbox - Reach UI
A listbox presents a list of selectable options in a popover, which is toggled on or off by a button. Visually and behaviorally...
Read more >
Portals - React
Portals. Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component....
Read more >
Using React Portals to build a modal - LogRocket Blog
Learn how to build a modal or overlay component in React with React Portals. Our demo is applicable for all top level components....
Read more >
useComboBox – React Aria
A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query....
Read more >
How to Prevent closing of modal Dialog in React ... - Syncfusion
Checkout and learn about Prevent closing of modal Dialog in React Dialog component of Syncfusion Essential JS 2, and more details.
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