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

fix(ui5-select): scroll item into view on keyboard navigation #7370

Merged
merged 8 commits into from
Aug 31, 2023
15 changes: 15 additions & 0 deletions packages/main/src/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,19 @@ class Select extends UI5Element implements IFormElement {
this._toggleRespPopover();
}

_scrollSelectedItem() {
if (this._isPickerOpen) {
const itemRef = this._currentlySelectedOption.getDomRef();
if (itemRef) {
itemRef.scrollIntoView({
behavior: "auto",
block: "nearest",
inline: "nearest",
});
}
}
}

_handleArrowNavigation(e: KeyboardEvent) {
let nextIndex = -1;
const currentIndex = this._selectedIndex;
Expand All @@ -835,6 +848,7 @@ class Select extends UI5Element implements IFormElement {
// The aria-activedescendents attribute can't be used,
// because listitem elements are in different shadow dom
this.itemSelectionAnnounce();
this._scrollSelectedItem();
}
}

Expand Down Expand Up @@ -882,6 +896,7 @@ class Select extends UI5Element implements IFormElement {
this.opened = true;
this.fireEvent<CustomEvent>("open");
this.itemSelectionAnnounce();
this._scrollSelectedItem();
}

_afterClose() {
Expand Down
18 changes: 18 additions & 0 deletions packages/main/test/specs/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ describe("Select general interaction", () => {
await firstItem.click();
assert.notOk(await popover.getProperty("opened"), "Select is closed.");
});

it("Tests if currently selected option is visible in the viewport when keyboard navigation is used", async () => {
await browser.setWindowSize(600, 100);

const select = await browser.$("#warningSelect");
const staticAreaItemClassName = await browser.getStaticAreaItemClassName("#warningSelect");
const popover = await browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover");

await select.click();
assert.ok(await popover.getProperty("opened"), "Select is opened.");

await select.keys("ArrowDown");
await select.keys("ArrowDown");
await select.keys("ArrowDown");

const selectedOption = await popover.$("ui5-list").$("ui5-li[selected]");
assert.ok(await selectedOption.isClickable(), "Selected option is visible in the viewport.");
});
});

describe("Attributes propagation", () => {
Expand Down