Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/scripts/clipperUI/components/sectionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class SectionPickerClass extends ComponentBase<SectionPickerState, Sectio
// If the user selects a section, onPopupToggle will fire because it closes the popup, even though it wasn't a click
// so logging only when they open it is potentially the next best thing
Clipper.logger.logClickEvent(Log.Click.Label.sectionPickerLocationContainer);
// Move focus to the first item in the dropdown when it opens
requestAnimationFrame(() => {
let notebookList = document.getElementById("notebookList");
if (notebookList) {
let firstTreeItem = notebookList.querySelector("li[role='treeitem']") as HTMLElement;
if (firstTreeItem) {
firstTreeItem.focus();
}
}
});
}
this.props.onPopupToggle(shouldNowBeOpen);
}
Expand Down
29 changes: 29 additions & 0 deletions src/tests/clipperUI/components/sectionPicker_tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,35 @@ export class SectionPickerSinonTests extends TestModule {
done();
});
});

test("onPopupToggle should move focus to first tree item when dropdown opens", (assert: QUnitAssert) => {
let done = assert.async();

let clipperState = MockProps.getMockClipperState();
let mockNotebooks = MockProps.getMockNotebooks();
initializeClipperStorage(JSON.stringify(mockNotebooks), undefined, TestConstants.defaultUserInfoAsJsonString);

let component = <SectionPicker
onPopupToggle={() => {}}
clipperState={clipperState} />;
MithrilUtils.mountToFixture(component);

// Open the dropdown
MithrilUtils.simulateAction(() => {
document.getElementById(TestConstants.Ids.sectionLocationContainer).click();
});

// Wait for requestAnimationFrame to complete
requestAnimationFrame(() => {
let notebookList = document.getElementById("notebookList");
ok(notebookList, "Notebook list should be present when dropdown is open");
if (notebookList) {
let firstTreeItem = notebookList.querySelector("li[role='treeitem']") as HTMLElement;
ok(firstTreeItem, "First tree item should exist in the notebook list");
}
done();
});
});
}
}

Expand Down
Loading