Skip to content

Commit

Permalink
Make sure we only wrap if there are multiple text or element child no…
Browse files Browse the repository at this point in the history
…des.
  • Loading branch information
zachleat committed Oct 4, 2023
1 parent a1dafb8 commit c11727d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ <h2>Using container queries</h2>
<td class="title"><a href="http://en.wikipedia.org/wiki/Titanic_(1997_film)">Titanic</a></td>
<td>2</td>
<td class="demo-numeric">1997</td>
<td>88%</td>
<td><!-- test -->88%</td>
<td>$2.1B <a href="">Link</a> test</td>
</tr>
<tr>
<td class="title"><a href="http://en.wikipedia.org/wiki/The_Avengers_(2012_film)">The Avengers</a></td>
<td>3</td>
<td class="demo-numeric">2012</td>
<td>92%</td>
<td><!-- test --><span>92%</span></td>
<td>$1.5B</td>
</tr>
<tr>
Expand Down
9 changes: 8 additions & 1 deletion table-saw.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ table-saw.${this._identifier} {

cell.setAttribute(this.attrs.label, labels[cell.cellIndex]);

let nodeCount = 0;
for(let n of cell.childNodes) {
// text or element node
if(n.nodeType === 3 || n.nodeType === 1) {
nodeCount++;
}
}
// wrap if this cell has child nodes for correct grid alignment
if(cell.firstElementChild) {
if(nodeCount > 1) {
let wrapper = document.createElement("div");
wrapper.classList.add(this.classes.wrap);
while(cell.firstChild) {
Expand Down

0 comments on commit c11727d

Please sign in to comment.