Skip to content

Commit 155b3d7

Browse files
Fix arrow key navigation to skip hidden items inside collapsed notebooks
Agent-Logs-Url: https://github.com/OneNoteDev/WebClipper/sessions/cd89f9f3-38d1-4b38-b360-6bc769e5bbbf Co-authored-by: KethanaReddy7 <257986085+KethanaReddy7@users.noreply.github.com>
1 parent 20594c7 commit 155b3d7

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/scripts/clipperUI/components/sectionPicker.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ export class SectionPickerClass extends ComponentBase<SectionPickerState, Sectio
8888
return;
8989
}
9090
e.preventDefault();
91+
// Only include visible items — exclude elements whose parent is inside a "Closed"
92+
// collapsed notebook or sectionGroup (children remain in the DOM but are hidden via CSS).
9193
let focusableItems = Array.from(
9294
sectionPickerPopup.querySelectorAll("[tabindex]:not([tabindex=\"-1\"])")
93-
) as HTMLElement[];
95+
).filter((el) => {
96+
let parent = (el as HTMLElement).parentElement;
97+
return !parent || !parent.closest(".Closed");
98+
}) as HTMLElement[];
9499
if (focusableItems.length === 0) {
95100
return;
96101
}

src/tests/clipperUI/components/sectionPicker_tests.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,65 @@ export class SectionPickerTests extends TestModule {
450450
clock.restore();
451451
done();
452452
});
453+
454+
test("onPopupToggle should skip hidden items inside closed notebooks when navigating with Down arrow", (assert: QUnitAssert) => {
455+
let done = assert.async();
456+
let clock = sinon.useFakeTimers();
457+
458+
let clipperState = MockProps.getMockClipperState();
459+
initializeClipperStorage(undefined, undefined);
460+
461+
let component = <SectionPicker onPopupToggle={() => {}} clipperState={clipperState} />;
462+
let controllerInstance = MithrilUtils.mountToFixture(component);
463+
464+
// Build a structure that mirrors the OneNotePicker DOM:
465+
// sectionPickerContainer
466+
// li.Notebook.Closed (notebook1, tabindex)
467+
// ul
468+
// li.Section (hiddenSection, tabindex) -- inside closed notebook
469+
// li.Notebook.Opened (notebook2, tabindex)
470+
let sectionPickerPopup = document.createElement("div");
471+
sectionPickerPopup.id = "sectionPickerContainer";
472+
473+
let notebook1 = document.createElement("li");
474+
notebook1.className = "Notebook Closed";
475+
notebook1.tabIndex = 70;
476+
let closedChildList = document.createElement("ul");
477+
let hiddenSection = document.createElement("li");
478+
hiddenSection.className = "Section";
479+
hiddenSection.tabIndex = 70;
480+
let hiddenSectionFocusCalled = false;
481+
hiddenSection.focus = () => { hiddenSectionFocusCalled = true; };
482+
closedChildList.appendChild(hiddenSection);
483+
notebook1.appendChild(closedChildList);
484+
485+
let notebook2FocusCalled = false;
486+
let notebook2 = document.createElement("li");
487+
notebook2.className = "Notebook Opened";
488+
notebook2.tabIndex = 70;
489+
notebook2.focus = () => { notebook2FocusCalled = true; };
490+
491+
sectionPickerPopup.appendChild(notebook1);
492+
sectionPickerPopup.appendChild(notebook2);
493+
document.body.appendChild(sectionPickerPopup);
494+
495+
controllerInstance.onPopupToggle(true);
496+
clock.tick(0);
497+
498+
// Press Down arrow from notebook1 — should jump to notebook2, skipping the hidden section inside notebook1
499+
notebook1.focus();
500+
let downKeyEvent = document.createEvent("KeyboardEvent");
501+
downKeyEvent.initEvent("keydown", true, true);
502+
Object.defineProperty(downKeyEvent, "which", { value: 40 });
503+
sectionPickerPopup.dispatchEvent(downKeyEvent);
504+
505+
ok(!hiddenSectionFocusCalled, "Hidden section inside a closed notebook should not receive focus");
506+
ok(notebook2FocusCalled, "Down arrow from a closed notebook should move focus to the next visible notebook");
507+
508+
document.body.removeChild(sectionPickerPopup);
509+
clock.restore();
510+
done();
511+
});
453512
}
454513
}
455514

0 commit comments

Comments
 (0)