Fix table borders when cells with `rowspan` are visually in the last row (#4176)
authorMatthias Schmidt <gravatronics@live.com>
Mon, 3 May 2021 10:27:17 +0000 (12:27 +0200)
committerGitHub <noreply@github.com>
Mon, 3 May 2021 10:27:17 +0000 (12:27 +0200)
See https://community.woltlab.com/thread/289598

wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeTable.class.php
wcfsetup/install/files/style/ui/tabularBox.scss

index 59a8097c38aeb1c6c4fc73625f9bb972bc9c0120..bc8feb5480339d462a7507089d5bd8fdf18820c5 100644 (file)
@@ -24,6 +24,33 @@ class HtmlOutputNodeTable extends AbstractHtmlOutputNode {
                if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') {
                        /** @var \DOMElement $element */
                        foreach ($elements as $element) {
+                               // Detect cells which are visually in the last row of a table due to their
+                               // `rowspan` property.
+                               /** @var \DOMElement $td */
+                               foreach ($element->getElementsByTagName('td') as $td) {
+                                       $rowspan = $td->getAttribute('rowspan');
+                                       if ($rowspan) {
+                                               $nextTrCount = 0;
+                                               $nextSibling = $td->parentNode->nextSibling;
+                                               while ($nextSibling) {
+                                                       if ($nextSibling->nodeType === \XML_ELEMENT_NODE && $nextSibling->tagName === "tr") {
+                                                               $nextTrCount++;
+                                                       }
+                                                       $nextSibling = $nextSibling->nextSibling;
+                                               }
+                                               
+                                               if ($rowspan - 1 === $nextTrCount) {
+                                                       $class = $td->getAttribute('class');
+                                                       if ($class) {
+                                                               $class .= " ";
+                                                       }
+                                                       $class .= "lastRow";
+                                                       
+                                                       $td->setAttribute('class', $class);
+                                               }
+                                       }
+                               }
+                               
                                // check if table is not contained within another table
                                $parent = $element;
                                while ($parent = $parent->parentNode) {
index 47941d07136c45b7f5434483fc852a0bba59e511..ec24d03de1fad0c0984de392ec8c80930a2726dc 100644 (file)
                        background-color: rgb(242, 242, 242);
                }
                
-               &:not(:last-child) > td {
+               &:not(:last-child) > td:not(.lastRow) {
                        border-bottom: 1px solid $wcfContentBorderInner;
                }
        }