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.

Dropdown cannot be opened again, if closed by clicking on the trigger button

See original GitHub issue

Relevant code or config:

import React, { useState } from "react";
import { Dropdown, DropdownItem } from "@windmill/react-ui";

interface Props {}

const UserDropdown = (props: Props) => {
  const [isProfileMenuOpen, setIsProfileMenuOpen] = useState(false);
  
  function handleProfileClick() {
    setIsProfileMenuOpen(!isProfileMenuOpen);
  }
  
  return (<div className="relative">
        <button
          className="rounded-full focus:shadow-outline-purple focus:outline-none"
          onClick={handleProfileClick}
          aria-label="Account"
          aria-haspopup="true"
        >
          Toggle
        </button>
        <Dropdown
          align="right"
          isOpen={isProfileMenuOpen}
          onClose={() => {
            setIsProfileMenuOpen(false);
          }}
        >
          <DropdownItem tag="a" href="#">
            User
          </DropdownItem>
          <DropdownItem tag="a" href="#">
            Settings
          </DropdownItem>
          <DropdownItem onClick={() => alert("Signout")}>
            Logout
          </DropdownItem>
        </Dropdown>
  </div>)
}

export default UserDropdown;

What you did:

Implemented a dropdown according to the full example of the documentation https://windmillui.com/react-ui/components/dropdown

What happened:

On first render, when user clicks on toggle button, then dropdown pops up. When user clicks the toggle button again, then the dropdown is closed. After the second click the dropdown cannot be opened again and remains closed.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
hademocommented, Feb 18, 2021

Update

@estevanmaito when debouncing the onClose handler of the Dropdown component the issue is solved. e.g.

const _ = require("lodash");
...
 <Dropdown
        align="right"
        isOpen={isProfileMenuOpen}
        onClose={_.debounce(() => setIsProfileMenuOpen(false), 300)}
        // onClose={() => setIsProfileMenuOpen(false)}
      >
  .....
</Dropdown>
2reactions
awesomeunleashedcommented, May 3, 2021

Not sure why, but forcing the button to be re-mounted when changing isOpen seems to fix this issue. The easiest way to do this is setting a key prop on the button that changes with isOpen (I used key={isOpen.toString()}).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot re-open the drop-down list by one click
There is a drop-down list and an iframe . The problem is that when the drop-down list is open, clicking on the iframe...
Read more >
Video: Trigger an animation effect - Microsoft Support
In the Animation Pane, select the animated shape or other object that you want to trigger to begin playing when you click it....
Read more >
Manage objects with the Selection pane
In the pane, select an item in the list. On the right side of the item, click the "open eye" button. The Open...
Read more >
Dropdowns · Bootstrap
Wrap the dropdown's toggle (your button or link) and the dropdown menu within .dropdown , or another element that declares position: relative; ....
Read more >
How to Create a Dropdown Menu in Adobe XD
Dropdown menus typically have two core states; open and closed. ... With the newly created component selected, click on the + button next...
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