Skip to content

Commit

Permalink
Only put the last visible TOC item as the tab stop.
Browse files Browse the repository at this point in the history
The code to find the last item in the TOC to put in the tabbing order
was including items under collapsed subgroups.

This changes the list to only look at items visible in the sidebar.
  • Loading branch information
christianp committed Jan 23, 2025
1 parent 8588714 commit bb55caf
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions chirun/themes/default/static/customisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ function treeview(element) {
e.preventDefault();
});

const all_items = [];

function get_children(el) {
const group = el.querySelector('[role="group"]');
return group ? group.children : [];
}

function find_all_items(el) {
const treeitem = el.querySelector('[role="treeitem"]');

all_items.push(treeitem);

if(treeitem.ariaExpanded == 'true') {
for(let child of get_children(el)) {
find_all_items(child);
}
}
}
find_all_items(element);


element.addEventListener('keydown', e => {
const modifier = e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;

Expand All @@ -261,26 +282,6 @@ function treeview(element) {
const siblings = Array.from(el.parentElement.children);
const i = siblings.indexOf(el);

const all_items = [];

function find_all_items(el) {
const treeitem = el.querySelector('[role="treeitem"]');

all_items.push(treeitem);

if(treeitem.ariaExpanded == 'true') {
for(let child of get_children(el)) {
find_all_items(child);
}
}
}
find_all_items(element);

function get_children(el) {
const group = el.querySelector('[role="group"]');
return group ? group.children : [];
}

function next_item(el) {
const treeitem = el.querySelector('[role="treeitem"]');
const children = get_children(el);
Expand Down Expand Up @@ -469,7 +470,7 @@ function treeview(element) {
}
}

const visible_items = element.querySelectorAll('.visible[role="treeitem"]');
const visible_items = all_items.filter(item => item.classList.contains('visible'));
if(visible_items.length) {
visible_items[visible_items.length-1].tabIndex = 0;
}
Expand Down

0 comments on commit bb55caf

Please sign in to comment.