[Table] - HeaderCell onClick prop is overwritten
See original GitHub issueIssue Description
Consumers wanting to implement sorting need to be able to pass an onClick to a Table’s HeaderCell. Currently the HeaderCell’s onClick is always overwritten by the click event of the Table.Header
https://github.com/cerner/terra-core/blob/master/packages/terra-table/src/TableHeader.jsx#L33
Issue Type
- New Feature
- Enhancement
- Bug
- Other
Expected Behavior
A Table.HeaderCell should honor an onClick directly passed.
Current Behavior
A Table.HeaderCell’s onClick is always overwritten by the onClick of the Table.Header.
<Table.Header>
<Table.HeaderCell content={'Name'} minWidth="small" sort="desc" onClick={() => console.log('This onClick will never be invoked')} />
<Table.HeaderCell content={'Address'} key={'ADDRESS'} minWidth={'medium'} />
<Table.HeaderCell content={'Phone Number'} key={'PHONE_NUMBER'} minWidth={'large'} />
</Table.Header>
Steps to Reproduce
- Create a Table
- Add an onClick to a Table.HeaderCell
- Observe the onClick is always overwritten,
Environment
- All environments
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
React Js: How to pass table row data as props to another ...
I want to pass the table row data as props to another page by clicking the buttons and display the data. But I...
Read more >Columns Props · react-bootstrap-table2
This prop allow you to replace the value when table sorting. ... It allows to customize the style of header cell when this...
Read more >A server side external sorting and filtering example #2033
In my case react-table is a reusable component, written in .tsx . So, in the Table component a function was passed as an...
Read more >Documentation - jsGrid
headercss is a string representing css classes to be attached to the table header cell. If not specified, then css is attached instead....
Read more >How to Replace Redux with React Hooks and the Context API
One of the biggest problems was “prop drilling”, which was common ... a single setValue() function for overwriting existing state values.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ll need to determine why the code was implemented this way to uncover if this was intentional functionality or an accidental bug. My assumption is this was written as a workaround to avoid a lint error when adding an onClick to a
<thead />
tag.I would expect both onClicks to be fired if the user added an onClick to both the Table.Header and the Table.HeaderCell. ( Although I think this is a rare use case, but one the consumer can handle )
Click events should bubble. Clicking any child of the Table.Header will invoke an onClick on the Table.Header naturally through event bubbling / propagation without doing the cloning logic here.
Something along these lines is what I had in mind for this change.
This is available in terra-table@2.3.0