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

Dropdown dismiss on click only works the first time #793

Closed
stuart-williams opened this issue Jun 3, 2023 · 7 comments · Fixed by #840
Closed

Dropdown dismiss on click only works the first time #793

stuart-williams opened this issue Jun 3, 2023 · 7 comments · Fixed by #840
Assignees

Comments

@stuart-williams
Copy link

Describe the bug
Dropdown dismiss on click only works the first time the dropdown menu is opened

To Reproduce

  1. Trigger drop down
  2. Clicking an item dismisses the menu as expected
  3. Trigger dropdown a second time
  4. Clicking an item does not dismiss the menu

Expected behavior
Clicking a dropdown menu item dismisses the menu consistently

Screenshots

Screen.Recording.2023-06-03.at.11.21.02.mov

System information:

  • Device: Mac
  • Resolution:
  • OS: Monterey
  • Browser: Chrome
  • Version: 114.0.5735.90

Project information:

  • Tailwind: 3.0.0
  • Flowbite: 1.4.7
  • Flowbite React: 0.1.2
  • Type: CRA

Additional context
Add any other context about the problem here.

@nbsp1221
Copy link

nbsp1221 commented Jun 5, 2023

Same problem for me. I think the cause of this issue is in Dropdown.tsx.

onClick: () => {
node.props.onClick?.();
dismissOnClick && setCloseRequestKey(id);
},

In order to dismiss the menu, setCloseRequestKey should be called with random id value. However, useId hook does not return a random value every time you click items.

image

When I replaced the useId hook with a random string generator as shown above, it worked fine.

I hope this information helps to resolve the issue.

@tulup-conner
Copy link
Collaborator

tulup-conner commented Jun 6, 2023

@nbsp1221 Thank you for catching that! I specifically undid that change and did not realize this is a thing that happens. That is my bad.

If someone wants to make a PR - please do! It should be as simple as doing exactly what @nbsp1221 did here, or something simpler to understand like, Math.random().toString(8).

My guess is that useId is supposed to work with React Server Components, but we're forcing use client for all of our components and breaking that behavior. That is likely the core issue, which we can and will resolve in the future, at which point we can use useId for its intended purpose here. See the second "pitfall" noted in https://react.dev/reference/react/useId#usage

@tulup-conner
Copy link
Collaborator

This is a duplicate of #625 but I didn't realize that and the proposed solution provided here is great so we can keep the discussion here.

@mansgori
Copy link

mansgori commented Jun 8, 2023

@tulup-conner Hi, I understand the problem. I want to working on this problem. can you assign to me?

mansgori added a commit to mansgori/flowbite-react that referenced this issue Jun 9, 2023
nigellima added a commit to gistia/flowbite-react that referenced this issue Jun 24, 2023
…smissOnClick is true

The dropdown component was not closing after after the first time it was opened and the items were
clicked. The closeRequestKey was not being updated after the first render

fix themesberg#793
@rluders
Copy link
Collaborator

rluders commented Jul 3, 2023

@nigellima are you working on this one? I noticed that you created a commit with a reference to this task. :)

@nigellima
Copy link
Collaborator

nigellima commented Jul 3, 2023

@nigellima are you working on this one? I noticed that you created a commit with a reference to this task. :)

Hey, yes. It's still in my local environment. But that commit in specific I will drop it, because I'm actually working on the #648 , which will solve this and some other issues related to the Dropdown component

@rluders
Copy link
Collaborator

rluders commented Jul 3, 2023

@nigellima all right. Thanks, I'll be waiting for your the PR. Valeu, jovem. :)

nigellima added a commit to gistia/flowbite-react that referenced this issue Jul 4, 2023
Now the Dropdownn component is accessible by keyboard. It also adds the support to disable the
trigger button. Also the dismiss on item click is fixed

fix themesberg#648. fix themesberg#793. fix themesberg#539

---------

Co-authored-by: Fatemeh Paghar <paghar.fatemeh@outlook.com>
nigellima added a commit to gistia/flowbite-react that referenced this issue Jul 4, 2023
Now the Dropdown component is accessible by keyboard. Also the dismiss on item click is fixed

fix themesberg#648. fix themesberg#793
nigellima added a commit to gistia/flowbite-react that referenced this issue Jul 6, 2023
Now the Dropdown component is accessible by keyboard. Also the dismiss on item click is fixed

fix themesberg#648. fix themesberg#793
rluders pushed a commit that referenced this issue Jul 6, 2023
* feat(button.tsx): created BaseButton component

This component is responsible to handle the logic of creating the button element based on the custom or default tag name

* feat(dropdown.tsx): enabled Dropdown to be accessible by keyboard

Now the Dropdown component is accessible by keyboard. Also the dismiss on item click is fixed

fix #648. fix #793

* feat(dropdown.tsx): removed div wrapper around trigger button

* feat(dropdown.tsx): moved renderTrigger function to Trigger

clone element resulted from renderTrigger and attach the ref and a11y props to it

* test(dropdown.tsx): updated and added more tests

Resolution for dependency nwsapi was added in order to fix an issue in the tababble package

* refact(floating.tsx): passed arrowRef to useBaseFloating custom hook

* fix(floating.tsx): readded focus interaction

* test(dropdown.tsx): added a delay in one of the test cases

* docs(dropdown.tsx): added stories and documentation section

* refact(dropdown.tsx): removed mergeWrapperClassName utility fn

* feat(dropdown.tsx): added theme customization support for menuitem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants