Skip to content

Commit 8ecd118

Browse files
authored
fix(ui5-select): scroll item into view on keyboard navigation (#7370)
* fix(ui5-select): scroll item into view on keyboard navigation Fixes: #7164
1 parent d3acd4b commit 8ecd118

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/main/src/Select.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,19 @@ class Select extends UI5Element implements IFormElement {
816816
this._toggleRespPopover();
817817
}
818818

819+
_scrollSelectedItem() {
820+
if (this._isPickerOpen) {
821+
const itemRef = this._currentlySelectedOption.getDomRef();
822+
if (itemRef) {
823+
itemRef.scrollIntoView({
824+
behavior: "auto",
825+
block: "nearest",
826+
inline: "nearest",
827+
});
828+
}
829+
}
830+
}
831+
819832
_handleArrowNavigation(e: KeyboardEvent) {
820833
let nextIndex = -1;
821834
const currentIndex = this._selectedIndex;
@@ -835,6 +848,7 @@ class Select extends UI5Element implements IFormElement {
835848
// The aria-activedescendents attribute can't be used,
836849
// because listitem elements are in different shadow dom
837850
this.itemSelectionAnnounce();
851+
this._scrollSelectedItem();
838852
}
839853
}
840854

@@ -882,6 +896,7 @@ class Select extends UI5Element implements IFormElement {
882896
this.opened = true;
883897
this.fireEvent<CustomEvent>("open");
884898
this.itemSelectionAnnounce();
899+
this._scrollSelectedItem();
885900
}
886901

887902
_afterClose() {

packages/main/test/specs/Select.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,24 @@ describe("Select general interaction", () => {
540540
await firstItem.click();
541541
assert.notOk(await popover.getProperty("opened"), "Select is closed.");
542542
});
543+
544+
it("Tests if currently selected option is visible in the viewport when keyboard navigation is used", async () => {
545+
await browser.setWindowSize(600, 100);
546+
547+
const select = await browser.$("#warningSelect");
548+
const staticAreaItemClassName = await browser.getStaticAreaItemClassName("#warningSelect");
549+
const popover = await browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover");
550+
551+
await select.click();
552+
assert.ok(await popover.getProperty("opened"), "Select is opened.");
553+
554+
await select.keys("ArrowDown");
555+
await select.keys("ArrowDown");
556+
await select.keys("ArrowDown");
557+
558+
const selectedOption = await popover.$("ui5-list").$("ui5-li[selected]");
559+
assert.ok(await selectedOption.isClickable(), "Selected option is visible in the viewport.");
560+
});
543561
});
544562

545563
describe("Attributes propagation", () => {

0 commit comments

Comments
 (0)