Skip to content

Commit 0e9ae90

Browse files
committed
MBS-10425: Add border coloring for active tab
1 parent ede3738 commit 0e9ae90

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

classes/header.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
346346
}
347347
}
348348

349+
// Store background-color for active tabs to use in border CSS.
350+
$activebackgroundcolor = null;
349351
foreach ($styles as $key => $value) {
350-
351352
// If exist a unit for the rule, apply it.
352353
if (isset($units[$key])) {
353354
$value = $value . $units[$key];
@@ -356,6 +357,11 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
356357
$value = $value . 'px';
357358
}
358359

360+
// Capture background-color from any type that has it.
361+
if ($key === 'background-color') {
362+
$activebackgroundcolor = $value;
363+
}
364+
359365
if ($key == 'others') {
360366
$onecss .= $value . ';';
361367
} else {
@@ -364,6 +370,23 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
364370
}
365371

366372
$onecss .= '} ';
373+
374+
// Add border CSS for .format_onetopic-tabs when this tab is active.
375+
// Apply the border to the tabs container when this specific tab is active.
376+
// Only generate CSS if a background color is defined.
377+
if (!empty($activebackgroundcolor) && ($type === 'active' || $type === 'default')) {
378+
$onecss .= '#tabs-tree-start:has(#onetabid-' . $thissection->id . ' a.nav-link.active) ';
379+
$onecss .= '.format_onetopic-tabs { ';
380+
$onecss .= 'border-bottom: 2px solid ' . $activebackgroundcolor . ' !important; ';
381+
$onecss .= 'padding-bottom: 1px; ';
382+
$onecss .= '} ';
383+
$onecss .= '#onetabid-' . $thissection->id . ' .nav-link.active { border-color: ' . $activebackgroundcolor . '; }';
384+
$onecss .= '#tabs-tree-start.verticaltabs .tabs-wrapper';
385+
$onecss .= ':has(#onetabid-' . $thissection->id . ' a.nav-link.active) ';
386+
$onecss .= '.format_onetopic-tabs { ';
387+
$onecss .= 'border-bottom: none !important; ';
388+
$onecss .= '}';
389+
}
367390
}
368391

369392
// Clean the CSS for html tags.

styles.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@
112112
}
113113
}
114114

115+
// Store background-color for active tabs to use in border CSS.
116+
$activebackgroundcolor = null;
115117
foreach ($styles as $key => $value) {
116-
117118
// If exist a unit for the rule, apply it.
118119
if (isset($units[$key])) {
119120
$value = $value . $units[$key];
@@ -122,6 +123,11 @@
122123
$value = $value . 'px';
123124
}
124125

126+
// Capture background-color for active tabs.
127+
if ($type === 'active' && $key === 'background-color') {
128+
$activebackgroundcolor = $value;
129+
}
130+
125131
if ($key == 'others') {
126132
$csscontent .= $value . ';';
127133
} else {
@@ -130,6 +136,14 @@
130136
}
131137

132138
$csscontent .= '} ';
139+
140+
// Add border CSS for .format_onetopic-tabs when processing active tab with background-color.
141+
if ($type === 'active' && !empty($activebackgroundcolor)) {
142+
$csscontent .= '#tabs-tree-start .format_onetopic-tabs { ';
143+
$csscontent .= 'border-bottom: 2px solid ' . $activebackgroundcolor . ' !important; ';
144+
$csscontent .= 'padding-bottom: 1px; ';
145+
$csscontent .= '} ';
146+
}
133147
}
134148

135149
// Clean the CSS for html tags.

0 commit comments

Comments
 (0)