[Listbox] ListboxPopover portal immediately closes first time it's opened within a Dialog. ( React 17+)
See original GitHub issue🐛 Bug report
Current Behavior
- With a Listbox visible in a Dialog, click the Listbox
- Listbox opens and closes immediatly.
- Click again.
- Listbox opens normally.
This seems to be fine in older versions of React, not working in 17.0.1
Expected behavior
- With a Listbox visible in a Dialog, click the Listbox
- Listbox opens normally.
Reproducible example
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:
- Created 3 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 🥇
@einaralex no need! Although I meant to add information for further exploration, I really don’t know the possible consequences of doing that.