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.

TableToolbarSearch: if I set a defaultValue, the onChange callback is called inconsistently

See original GitHub issue

TableToolbarSearch calls onChange back differently if a defaultValue is set, than when the actual value is typed, this required two different versions of my onChange handler

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

The callback onChange code when an event is typed comes back like this

onChange(event)

but when a default value is set, it is called like this

onChange(‘’,defaultValue)

Here’s my workaround to handle both cases <TableToolbarSearch defaultValue=‘mydefaultvalue’ onChange={(event, defaultValue) => onApplySearch(defaultValue || event.currentTarget ? event.currentTarget.value : ‘’) } />

Is this issue related to a specific component? TableToolbarSearch

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

What browser are you working in? Chrome

What version of the Carbon Design System are you using? 10.12.0

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tay1orjonescommented, Aug 4, 2020

Correct, and yeah I personally feel that the signature is fine as is with maybe the change to undefined/null instead of empty string for the missing event object.

Thanks for the response regarding the key too, that was confusingly tied up in a related bug in our repo but we got the clarity needed through the related PR #6517 and then fixed on our end https://github.com/carbon-design-system/carbon-addons-iot-react/pull/1406

0reactions
emyarodcommented, Jul 22, 2020

I’ve lost a lot of the issue context over the last 2 months so just to clarify:

no action is needed for the onChange handler regardless of whether or not a defaultValue is specified right? since no event object would be available if a default value is being used. is the callback function signature fine as is? (aside from maybe using null/undefined rather than empty string in place of the missing event object)

regarding the note about updating when a new defaultValue is used, I believe the method with using a key is the correct method since defaultValue is only read on component mount IIRC (https://github.com/facebook/react/issues/4101#issuecomment-111307019).

Read more comments on GitHub >

github_iconTop Results From Across the Web

OnChange event on controls not consistent when default ...
It seems that some controls don't fire the OnChange action when the default value property is set/bound to an output from a component:....
Read more >
Setting the default value of an input field after data is retrieved ...
You need to replace the 'defaultValue' attribute with 'value' in the inputs. You are using a controlled vs uncontrolled component.
Read more >
You provided 'value' prop to a form field without onChange ...
The defaultValue prop sets an initial value for the input field, but the value is not static and can be changed.
Read more >
Form - Set field default value using Javascript - ServiceNow
On the change request form, i have a field called "Change Owner". ... it done through onChange() client, let's try and see if...
Read more >
TextInput · React Native
The default value is true for single-line fields and false for multiline fields. ... onBlur. Callback that is called when the text input...
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