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 item onClick not firing when clicked

See original GitHub issue

I’m passing down an array of items to a Dropdown component and for each I’m defining the value as a function. However, the onClick event doesn’t get called when I click the item. I found that if I made a small adjustment to line 105 of Dropdown Component it works:

Current implementation: { className: 'Dropdown-menu__action', onClick: self.onClick.bind(self, item.value) },

Working Implementation: { className: 'Dropdown-menu__action', onClick: item.value },

Thanks for this nice looking UI kit!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
clschneicommented, Sep 25, 2017

This definitely not a bug. So we can probably close this ticket.

But to resolve your issue @jonathanwmaddison, you have two problems:

  1. You need to add an onSelect prop to alert the parent component that a value has been selected.
  2. Now you can either:
    • call the function in your parent callback handler
    handleSelect(value) { 
      value() // will map to your items array "value"
    }
    
    <Dropdown onSelect={this.handleSelect} />
    
    • OR build those functions into your parent component class and use string values to direct your logic flow

Should fix your problem.

0reactions
jonathanwmaddisoncommented, Sep 25, 2017

@clschnei Thank you for the suggestions and for looking at my code so quickly. Hopefully this will help other coders with the same problem, and missed how to do this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OnClick event not working in dropdown option - Stack Overflow
I have dropdown, When I choose option it will retrieve value from database and will shown on text feild. So I did Click...
Read more >
The DropdownItem child do NOT get the click event #54 - GitHub
I updated the docs locally to wrap the text within the DropdownItem in a div with an onClick and it seems to be...
Read more >
Button click is not working when dropdown value is selected
I am filling a drop down values using jquery and whenever i am selecting the values in that drop down, my server button...
Read more >
React onClick event is not firing on bootstrap dropdown menu ...
You need e.preventDefault() in the click handler. It's firing but the default behavior of an anchor is to refresh the page, so it's...
Read more >
onSelect event for react dropdown component
Thank you Anna,. But this does not change the MDBDropdownItem to the active class when clicked.
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