Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@
margin-top: 0.25em;
}

.table.block.center-align table thead tr p {
width:900px;
}

.table.block.center-align table thead tr {
min-height: 30px;
width: 75%;
text-align: center;
}

Expand Down Expand Up @@ -183,9 +178,6 @@
margin: 0 0 12px;
}

.table.block.center-align table thead tr p {
width:600px;
}

.table.block.center-align table tbody tr.single-column-row td p{
width: 600px;
Expand Down Expand Up @@ -216,6 +208,10 @@
vertical-align: top;
}

.table.block.center-align table th.col-4, .table.block.center-align table td.col-4 {
vertical-align: top;
}

.table.block.center-align table th.col-5, .table.block.center-align table td.col-5 {
vertical-align: top;
}
Expand Down Expand Up @@ -249,9 +245,6 @@
}


.table.block.center-align table thead tr p {
width:700px;
}

.table.block table th.col-1, .table.block table td.col-1 {
width: 30%;
Expand Down
8 changes: 8 additions & 0 deletions blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default async function decorate(block) {
const tbody = document.createElement('tbody');
const header = !block.classList.contains('no-header');

// Determine max column count from all rows
const maxCols = Math.max(...[...block.children].map((row) => row.children.length));

[...block.children].forEach((row, i) => {
const tr = document.createElement('tr');
moveInstrumentation(row, tr);
Expand All @@ -38,6 +41,11 @@ export default async function decorate(block) {
// Add column index class for targeting specific columns with CSS
td.classList.add(`col-${colIndex + 1}`);

// When row has fewer cells than max, add colspan so single-cell rows span full table width
if (cells.length < maxCols && colIndex === cells.length - 1) {
td.setAttribute('colspan', maxCols - cells.length + 1);
}

// Check if cell has a data-width attribute and apply it
const cellWidth = cell.getAttribute('data-width');
if (cellWidth) {
Expand Down
Loading