Fixed tabs

main
Igor Scheller 3 years ago committed by Michael Weimann
parent 3fcf5c521c
commit 0398efad65
No known key found for this signature in database
GPG Key ID: 34F0524D4DA694A1

@ -38,25 +38,31 @@ function tabs($tabs, $selected = 0)
$tab_header = []; $tab_header = [];
$tab_content = []; $tab_content = [];
foreach ($tabs as $header => $content) { foreach ($tabs as $header => $content) {
$class = ''; $active = false;
$id = $header; $id = $header;
$href = '#' . $id; $href = '#' . $id;
if (count($tab_header) == $selected) { if (count($tab_header) == $selected) {
$class = 'active'; $active = true;
} }
if (is_array($content)) { if (is_array($content)) {
$href = $content['href']; $href = $content['href'];
$content = null; $content = null;
$id = null; $id = null;
} }
$tab_header[] = '<li role="presentation" class="' . $class . '"> $tab_header[] = '<li role="presentation" class="nav-item">
<a href="'. $href . '"' <a href="'. $href . '" class="nav-link' . ($active ? ' active' : '') . '" role="tab"'
. ($id ? ' aria-controls="' . $id . '" role="tab" data-toggle="tab"' : '') . ($id ? ' id="' . $id . '-tab"' : '')
. ($id ? ' aria-controls="' . $id . '" data-bs-target="#' . $id . '" data-bs-toggle="tab" role="tab"' : '')
. ($id && $active ? ' aria-selected="true"' : ' aria-selected="false"')
. '>' . '>'
. $header . '</a></li>'; . $header . '</a></li>';
$tab_content[] = $content ? '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $id . '">' $tab_content[] = $content
? '<div role="tabpanel" class="tab-pane' . ($active ? ' show active' : '') . '" id="' . $id . '"'
. ' aria-labelledby="' . $id . '-tab"'
. '>'
. $content . $content
. '</div>' : ''; . '</div>'
: '';
} }
return div('', [ return div('', [
'<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>', '<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>',

Loading…
Cancel
Save