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

[Bug]: Clicking on a dropdown trigger twice+ times consecutively causes unexpected results #456

Closed
3 tasks done
warrenspe opened this issue Feb 21, 2024 · 6 comments
Closed
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@warrenspe
Copy link

warrenspe commented Feb 21, 2024

Before submitting...

Context

Noticed this when developing a navbar with a dropdown in it; clicking on the icon to open the dropdown twice would prevent the dropdown from being available to the user unless they click elsewhere

Current Behavior

If one clicks on a dropdown trigger to open the dropdown, then one or more times, on the subsequent clicks it causes the dropdown to close, open again, then immediately close.

Expected behavior

If the dropdown is currently open, clicking on the trigger should close it. If it's closed, it should open

Possible Solutions or Causes

No response

Steps to reproduce

This behaviour can be seen in the demo in the docs
https://materializeweb.com/dropdown.html#options
Click on the Left DropDown! button two or more times in a row without clicking elsewhere on the page

Your Environment

  • Version used: 2.0.3
  • Browser Name and version: Chrome 122.0.6261.57
  • Operating System and version (desktop or mobile): Desktop
  • Additional information you want to tell us:
@warrenspe warrenspe added the bug Something isn't working label Feb 21, 2024
@warrenspe
Copy link
Author

This behaviour is also seen in the select component:
https://materializeweb.com/select.html

If one clicks on any of the selects more than once, on subsequent clicks the dropdown menu will appear and disappear preventing the user from being able to choose an option

@warrenspe
Copy link
Author

I'd be happy to investigate this and attempt to provide a PR; but would need to know, if a user clicks on a select/dropdown 2+ times, what would we expect to happen?

The two contenders that come to mind are:

  • The dropdown closes on the 2nd click, re-opens on the third, ...
  • The dropdown remains open on the 2nd and any subsequent clicks

@Jerit3787
Copy link

Jerit3787 commented Mar 5, 2024

I'd be happy to investigate this and attempt to provide a PR; but would need to know, if a user clicks on a select/dropdown 2+ times, what would we expect to happen?

The two contenders that come to mind are:

  • The dropdown closes on the 2nd click, re-opens on the third, ...
  • The dropdown remains open on the 2nd and any subsequent clicks

For this, I think we should close the dropdown once it is open. The issue here might have been the saving of the states of the dropdown.

thank you for helping with this issue :)

@wuda-io
Copy link
Member

wuda-io commented Mar 5, 2024

Hello @warrenspe thanks for your investigation. This is a bug and it would be awesome if you can provide a PR which would fix that. As @Jerit3787 already said, I also tend towards the first behaviour:

The dropdown closes on the 2nd click, re-opens on the third, ...

Looking forward to review the changes.

@wuda-io
Copy link
Member

wuda-io commented Mar 5, 2024

I saw that there is already a PR open #452
Does this fix the issue, please confirm so we do not have to do the work twice. Maybe there is also a cleaner solution instead of using a setTimeout Workaround. Wdyt?

@warrenspe
Copy link
Author

warrenspe commented Mar 6, 2024

Didn't test out the solution in #452 (I'm guessing it might not fix the select/label issue); but can confirm that some sort of setTimeout solution will probably be necessary due to the way handleClick/handleDocumentClick operate

Clicking on the trigger calls both _handleClick and _handleDocumentClick; this can be worked around by looking at e.target, but not if a label for a select was clicked (which also calls both _handleClick and _handleDocumentClick)

@wuda-io wuda-io closed this as completed in a100e39 Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants