Skip to content

Commit

Permalink
Apply headings to <th> in body too. Trim labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Oct 4, 2023
1 parent 2b531d9 commit 9c8cf7d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions table-saw.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ table-saw.${this._identifier} {
}

addHeaders() {
let labels = Array.from(this.querySelectorAll("thead th")).map(entry => entry.innerText);
let labels = Array.from(this.querySelectorAll("thead th")).map(entry => entry.innerText.trim());
if(labels.length === 0) {
this._needsStylesheet = false;
console.error("No `<th>` elements for Tablesaw were found:", this);
return;
}

let cells = this.querySelectorAll("tbody td");
let cells = this.querySelectorAll("tbody :is(td, th)");
for(let cell of cells) {
if(!labels[cell.cellIndex]) {
continue;
}

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

// wrap if this cell has child nodes for correct grid alignment
Expand Down

0 comments on commit 9c8cf7d

Please sign in to comment.