From c11727d40ead70f36a9fdc28682b325d809f2620 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 4 Oct 2023 14:22:00 -0500 Subject: [PATCH] Make sure we only wrap if there are multiple text or element child nodes. --- demo.html | 4 ++-- table-saw.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/demo.html b/demo.html index 5e28105..a65eb8c 100644 --- a/demo.html +++ b/demo.html @@ -139,14 +139,14 @@

Using container queries

Titanic 2 1997 - 88% + 88% $2.1B Link test The Avengers 3 2012 - 92% + 92% $1.5B diff --git a/table-saw.js b/table-saw.js index 0da039d..ec71471 100644 --- a/table-saw.js +++ b/table-saw.js @@ -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) {