Skip to content

Commit

Permalink
Merge pull request #57 from hlxsites/feature/table-bugs
Browse files Browse the repository at this point in the history
Fixed the table issues
  • Loading branch information
pardeepgera23 authored Oct 27, 2023
2 parents 692061f + 337c188 commit 4ed9609
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ table td {
}

.heading-top tr:first-child td {
background-color: var(--primary-color); /* Specify your desired background color here */
background-color: var(--primary-color);
}

.heading-left tr td:first-child {
.left-heading {
background-color: var(--primary-color);
text-align: left;
}
Expand Down
17 changes: 17 additions & 0 deletions blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ function removeClassesFromChildTables(table) {
}

export default function decorate(block) {
const getHeadingLeftClass = block.classList.contains('heading-left');
if (getHeadingLeftClass !== null && getHeadingLeftClass !== undefined) {
const tds = block.querySelectorAll('tr td:first-child');
let index = 0;
while (index < tds.length) {
const td = tds[index];
td.classList.add('left-heading');
const rowspan = td.getAttribute('rowspan');
if (rowspan !== null && rowspan > 1) {
const rowspanCount = parseInt(rowspan, 10);
index += rowspanCount;
} else {
index += 1;
}
}
}

const tableRows = block.querySelectorAll('.table[data-block-name="table"] tr');
tableRows.forEach((row) => {
const cells = row.querySelectorAll('td');
Expand Down

0 comments on commit 4ed9609

Please sign in to comment.