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

Keyboard navigation should be improved. #6422

Merged
merged 1 commit into from
Jun 23, 2023
Merged
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
6 changes: 4 additions & 2 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ActionContainer } from "./actions/container";
import { Action, BaseAction, IAction } from "./actions/action";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { ElementHelper } from "./element-helper";
import { getFirstVisibleChild } from "./utils/utils";

export let defaultListCss = {
root: "sv-list__container",
Expand Down Expand Up @@ -203,8 +204,9 @@ export class ListModel<T extends BaseAction = Action> extends ActionContainer<T>
if (event.key === "ArrowDown" || event.keyCode === 40) {
const currentElement = (<HTMLElement>event.target).parentElement;
const listElement = currentElement.parentElement.querySelector("ul");
if (!!listElement && !!listElement.firstElementChild) {
ElementHelper.focusElement(listElement.firstElementChild);
const firstChild = getFirstVisibleChild(listElement);
if (!!listElement && !!firstChild) {
ElementHelper.focusElement(firstChild);
event.preventDefault();
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ function isContainerVisible(el: HTMLElement) {
);
}

function getFirstVisibleChild(el: HTMLElement) {
let result;
for(let index = 0; index < el.children.length; index++) {
if(!result && getComputedStyle(el.children[index]).display !== "none") {
result = el.children[index];
}
}
return result;
}
function findParentByClassNames(element: HTMLElement, classNames: Array<string>): Element {
if (!!element) {
if (classNames.every(className => !className || element.classList.contains(className))) {
Expand Down Expand Up @@ -376,4 +385,5 @@ export {
getOriginalEvent,
preventDefaults,
findParentByClassNames,
getFirstVisibleChild,
};
32 changes: 31 additions & 1 deletion testCafe/components/popup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { url, initSurvey, frameworks } from "../helper";
import { url, initSurvey, frameworks, getListItemByText } from "../helper";
import { Selector, ClientFunction } from "testcafe";
const title = "popup";

Expand Down Expand Up @@ -362,4 +362,34 @@ frameworks.forEach(async framework => {
.expect(popupSelector.visible).ok()
.expect(popupSelector.offsetHeight).within(popupHeight - 1, popupHeight + 1);
});

test("list model", async t => {
await initSurvey(framework, json, { onGetQuestionTitleActions: (_, opt) => {
const getItems = (count, startIndex = 0) => {
const list = [];
for (let index = startIndex; index < count; index++) {
list[index - startIndex] = new window["Survey"].Action({ id: index, title: "item" + index, needSeparator: index % 4 == 1 });
}
return list;
};
const dropdownWithSearchAction = window["Survey"].createDropdownActionModel(
{ title: "Long List", showTitle: true },
{ items: getItems(40), showPointer: true }
);
opt.titleActions = [dropdownWithSearchAction];
} });

const listItems = Selector(".sv-list__item").filterVisible();

await t
.click(Selector(".sv-action-bar-item"))
.expect(listItems.count).eql(40)

.pressKey("1")
.expect(listItems.count).eql(13)
.expect(getListItemByText("item1").focused).notOk()

.pressKey("down")
.expect(getListItemByText("item1").focused).ok();
});
});