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.

DataTable: Stop using <div> inside <thead>

See original GitHub issue

Question 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tay1orjonescommented, Jul 13, 2022

validateDOMNesting expects children of thead to be one of tr, style, script, or template per the html spec (source)

0reactions
wkeesecommented, Jul 14, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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