Send correct value of sortDirection
on the handleSortBy
callback
#4704
Labels
component: data-table
package: react
carbon-components-react
severity: 3
https://ibm.biz/carbon-severity
type: bug 🐛
Title line template: The
handleSortBy
callback receives the old value ofsortDirection
kept in state because it's being called before thesetState
function finishes.What package(s) are you using?
carbon-components
(10.5.1)carbon-components-react
(7.3.2)Detailed description
The provided
handleSortBy
callback provides the old value forsortDirection
as an input argument to the function because it does not wait for the state to change.Over here, the
sortDirection
comes straight from the state and does not wait for the state change.Would it be possible to move the callback call in the
setState
callback of thehandleSortBy
method so that it receives the correct value? Or call the callback with thegetNextSortState(sortDirection)
so that we get the correct value.Right now I have to make a weird mapping knowing that when I get the
"NONE"
direction, the user actually clicked the sort and it should be done in ascending order ("ASC"
). The mapping looks like this:This is pretty weird and unintuitive. I would like to refrain from keeping a separate manager in the app for the sort logic.
DataTable, TableHeader
I expected to get the real value of
sortDirection
in thehandleSortBy
callback instead of the old one.Steps to reproduce the issue
onClick
property on the TableHeaderExample:
https://codesandbox.io/s/priceless-waterfall-siw97
Notice the console.log output
The text was updated successfully, but these errors were encountered: