TableToolbarSearch: if I set a defaultValue, the onChange callback is called inconsistently
See original GitHub issueTableToolbarSearch 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:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
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/1406I’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 adefaultValue
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 sincedefaultValue
is only read on component mount IIRC (https://github.com/facebook/react/issues/4101#issuecomment-111307019).