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.

ComboBox onClick does not trigger with null selectedItem when items is objects

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

I have noticed that, when passing in an array of objects into the ComboBox’s items prop, that when the selectedItem prop is set to null, the onClick event handler is not called when you click the clear button. Any other case, that event handler is called when selecting an item from the drop down or clicking the clear filter/button in the search field except when that prop has null passed inside. I found this out when I used null to reset it.

Is this issue related to a specific component?

ComboBox

What did you expect to happen? What happened instead? What would you like to

I learned that resetting the value to appear within the combobox by default via selectedItem works when passing in an empty object, but it took me a while to figure this out due to thinking null should work fine. So I would expect null to work the same as an empty object.

Steps to reproduce the issue

I set up a sandbox with different scenarios commented out

https://codesandbox.io/s/optimistic-bas-6ovuo?file=/src/index.js

Additional information

This may not even be a bug, or if it is a very low one, but if it is not a bug, then it should be made aware the behavior differences between passing in null vs an object (or empty object in this case)

thank you!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
TannerScommented, Nov 20, 2021

Hey @TannerS I think I’m understanding the issue. I have a few questions:

* Is the example in your codesandbox representing the combobox that populates the second combobox or the second one that's dynamically populated? It might help to see an example of how you're doing this since it's specific to this situation.

* you mention in your first comment that you're resetting the selectedItem to null. I think it could be considered a bug, maybe, since it works as expected if you reset it to an empty object. I'm wondering if this is an acceptable workaround?

Hey, I won’t lie, it’s been a while since I looked at this I forgot my logic in the issue, however, looking at my comments in the sandbox, i no longer see the issue as described in the comments and noticed the sandbox is set to use the latest carbon react components.

With the fact I dont remember the exact details, i can’t recreate it in the latest version as per described in the comments, and it was avery specific situations, I think it is safe to say we could probably close this

0reactions
jnm2377commented, Nov 8, 2021

Hey @TannerS I think I’m understanding the issue. I have a few questions:

  • Is the example in your codesandbox representing the combobox that populates the second combobox or the second one that’s dynamically populated? It might help to see an example of how you’re doing this since it’s specific to this situation.
  • you mention in your first comment that you’re resetting the selectedItem to null. I think it could be considered a bug, maybe, since it works as expected if you reset it to an empty object. I’m wondering if this is an acceptable workaround?
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - What event handler to use for ComboBox Item Selected ...
(Clarification: Problem is how to trigger "something" when the same item is being selected again. No duplicates in the drop down list. Scenario:...
Read more >
ComboBox's SelectedValue doesn't update the bound ...
I've a ComboBox in one of my Views: <ComboBox Grid.Row="1"; IsSynchronizedWithCurrentItem="True"; ItemsSource="{Binding VacantSpaces}" ...
Read more >
Select - Ant Design
Select component to select value from options. When To Use. A dropdown menu for displaying choices - an elegant alternative to the native...
Read more >
Select | Quasar Framework
The QSelect Vue component has two types of selection - single or multiple. This component opens up a menu for the selection list...
Read more >
Binding DropDownList Value to complex model in UI for Blazor
By the way: if OnChange would use an event args object holding the selected item and selected value, that would also help a...
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