Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open top-level singleton collection by default in hierarchy tree #4201

9 changes: 7 additions & 2 deletions themes/bootstrap5/templates/hierarchy/tree.phtml
Original file line number Diff line number Diff line change
@@ -29,15 +29,20 @@
// Use escapeHtml for performance (this data shouldn't contain anything that escapeHtmlAttr would be useful with)
$escapeAttr = $escape;
$truncate = $this->plugin('truncate');
$nodeCount = count($nodes);
foreach ($nodes as $node) {
$hasChildren = !empty($node->children);
$liClasses = [];
$openTopLevel = false;
if ($hasChildren) {
$liClasses[] = 'hierarchy-tree__parent';
}
if ('collection' === $node->type) {
$liClasses[] = 'hierarchy-tree__collection';
$icon = 'hierarchy-collection';
if ($nodeId === 0 && !$parentNodeId && $nodeCount === 1) {
$openTopLevel = true;
}
} else {
$liClasses[] = 'hierarchy-tree__record';
$icon = 'hierarchy-record';
@@ -63,13 +68,13 @@
++$nodeId;
$childUlIdEsc = $escapeAttr('hierarchy_' . $context . '_' . $parentNodeId . '_' . $nodeId);
echo '<button class="hierarchy-tree__toggle-expanded js-toggle-expanded"'
. ' aria-expanded="' . ($node->hasSelectedChild ? 'true' : 'false') . '"'
. ' aria-expanded="' . ($node->hasSelectedChild || $openTopLevel ? 'true' : 'false') . '"'
. ' aria-controls="' . $childUlIdEsc . '"'
// Use node title as button label so that a screen reader can read it as
// "Expanded <text>" or "Collapsed <text>":
. ' aria-label="' . $escapeAttr($node->title) . '"'
. ' data-toggle-aria-expanded'
. ' data-default-expanded="' . ($node->hasSelectedChild ? 'true' : 'false') . '"'
. ' data-default-expanded="' . ($node->hasSelectedChild || $openTopLevel ? 'true' : 'false') . '"'
. '>'
. $icons['hierarchy-expand']
. $icons['hierarchy-collapse']