DataTable: Stop using <div> inside <thead>
See original GitHub issueQuestion for Carbon
The DataTable’s header has a <div>
inside a <th>
, which is apparently invalid HTML. It can be seen on https://react.carbondesignsystem.com/?path=/story/components-datatable-basic--default.
<thead>
<tr>
<th scope="col">
<div class="cds--table-header-label">Name</div>
</th>
...
Can/should it be changed to a <span>
?
It gives us spurious console errors and errors running our unit tests (which is bad because it masks any real errors that might occur):
Warning: validateDOMNesting(...): <div> cannot appear as a child of <thead>.
in div (created by DatagridHead)
in thead (created by TableHead)
in TableHead (created by DatagridHead)
in DatagridHead (created by Datagrid)
in table (created by Table)
in div (created by Table)
in Table (created by Datagrid)
Note: it’s the same problem in both Carbon 10 and Carbon 11.
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How can I remove the div tags from a html table using jquery ...
Use $('#datatable div').contents().unwrap() to remove the divs from the table and alert($('#datatable').html()) to show the remaining ...
Read more >DOM positioning - DataTables example
In the example below, the table information is moved to the top of the table, and all the interaction elements to the bottom,...
Read more ><thead>: The Table Head element - HTML - MDN Web Docs
The HTML element defines a set of rows defining the head of the columns of the table.
Read more >A table with both a sticky header and a sticky first column
“you can't position tr or thead” is not true in Firefox/Safari, and is a crbug.com/702927 in Chrome. Chrome's table rewrite is almost done,...
Read more >How to create a table with fixed header and scrollable body
By setting the display to “block” for both <thead> and <tbody> element so that we can apply the height and overflow properties to...
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
validateDOMNesting
expects children ofthead
to be one oftr
,style
,script
, ortemplate
per the html spec (source)Whoops, you’re right, I was misinterpreting the error message. So it’s
DatagridHead
’s fault, which is adding a<div>
as a direct child of the<thead>
. The code comment says “block element needed for sticky header and scrolling of body”, although I’m not sure if that’s really true. In any case, not carbon’s fault.