Skip to content

Commit e835e02

Browse files
committed
Mbs 10425 add border color for active tab (#2)
1 parent ace97b5 commit e835e02

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

classes/header.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
309309
$cssparentid = '[data-tabid="' . $thissection->id . '"]';
310310
$cssid = '#onetabid-' . $thissection->id . '';
311311
$withunits = ['font-size', 'line-height', 'margin', 'padding', 'border-width', 'border-radius'];
312+
$childsbackgroundcolor = null;
312313
foreach ($orderedtabs as $type => $styles) {
313314
$important = false;
314315
switch ($type) {
@@ -362,6 +363,8 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
362363
}
363364
}
364365

366+
// Store background-color for active tabs to use in border CSS.
367+
$activebackgroundcolor = null;
365368
foreach ($styles as $key => $value) {
366369
// If exist a unit for the rule, apply it.
367370
if (isset($units[$key])) {
@@ -371,6 +374,15 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
371374
$value = $value . 'px';
372375
}
373376

377+
// Capture background-color from any type that has it.
378+
if ($key === 'background-color') {
379+
$activebackgroundcolor = $value;
380+
// Also capture child background color for parent tab border rules.
381+
if ($type === 'childs') {
382+
$childsbackgroundcolor = $value;
383+
}
384+
}
385+
374386
if ($key == 'others') {
375387
$onecss .= $value . ';';
376388
} else {
@@ -379,6 +391,58 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
379391
}
380392

381393
$onecss .= '} ';
394+
395+
// Add border CSS for .format_onetopic-tabs when this tab is active.
396+
// Apply the border to the tabs container when this specific tab is active.
397+
// Only generate CSS if a background color is defined.
398+
if (!empty($activebackgroundcolor) && ($type === 'active' || $type === 'default')) {
399+
// Add border bottom for horizontal tabs.
400+
$onecss .= '#tabs-tree-start:has(#onetabid-' . $thissection->id . ' a.nav-link.active) ';
401+
$onecss .= '.format_onetopic-tabs { ';
402+
$onecss .= 'border-bottom: 2px solid ' . $activebackgroundcolor . ' !important; ';
403+
$onecss .= 'padding-bottom: 1px; ';
404+
$onecss .= '} ';
405+
$onecss .= '#onetabid-' . $thissection->id . ' .nav-link.active { ';
406+
$onecss .= 'border-color: ' . $activebackgroundcolor . '; } ';
407+
// Deny border for parent tab.
408+
$onecss .= '#tabs-tree-start .tabs-wrapper .format_onetopic-tabs:has(';
409+
$onecss .= '#onetabid-' . $thissection->id . '.haschilds a.nav-link.active) ';
410+
$onecss .= '{ ';
411+
$onecss .= 'border-bottom: 2px solid lightgray !important; ';
412+
$onecss .= '} ';
413+
// Add border left for vertical tabs.
414+
$onecss .= '#tabs-tree-start.verticaltabs .tabs-wrapper';
415+
$onecss .= ':has(#onetabid-' . $thissection->id . ' a.nav-link.active) ';
416+
$onecss .= '.format_onetopic-tabs { ';
417+
$onecss .= 'border-bottom: none !important; ';
418+
$onecss .= '}';
419+
420+
// If this is a child tab (level 1) with its own background, override parent's child color.
421+
if (isset($formatoptions['level']) && $formatoptions['level'] == 1) {
422+
// Override parent's child background color rule with this child's specific color.
423+
$onecss .= '#tabs-tree-start#tabs-tree-start#tabs-tree-start:has(';
424+
$onecss .= '#onetabid-' . $thissection->id . ' a.nav-link.active) ';
425+
$onecss .= '.onetopic-tab-body > ul.format_onetopic-tabs { ';
426+
$onecss .= 'border-bottom: 2px solid ' . $activebackgroundcolor . ' !important; ';
427+
$onecss .= 'padding-bottom: 1px !important; ';
428+
$onecss .= '} ';
429+
}
430+
}
431+
}
432+
433+
// Add border for child tabs if parent defines childs background color.
434+
// Generate this CSS after processing all style types for this section.
435+
if (!empty($childsbackgroundcolor)) {
436+
// Target the second row tabs when a child is active.
437+
// Use multiple IDs and very specific path to maximize specificity beyond parent rule.
438+
$childrule = '#tabs-tree-start#tabs-tree-start:has(.onetopic-tab-body';
439+
$childrule .= $cssparentid . ' .nav-item.subtopic a.nav-link.active) ';
440+
$childrule .= '.onetopic-tab-body' . $cssparentid . ' > ul.format_onetopic-tabs { ';
441+
$childrule .= 'border-bottom: 2px solid ' . $childsbackgroundcolor . ' !important; ';
442+
$childrule .= 'padding-bottom: 1px !important; ';
443+
$childrule .= '} ';
444+
445+
$onecss .= $childrule;
382446
}
383447

384448
// Clean the CSS for html tags.

0 commit comments

Comments
 (0)