Skip to content

Commit

Permalink
fix: make first item focusable when selected is negative (#7574) (#7575)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Jul 19, 2024
1 parent 821e80d commit 35c00c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/a11y-base/src/list-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export const ListMixin = (superClass) =>
}
});

this._setFocusable(selected || 0);
// When selected is set to -1, focus the first available item.
this._setFocusable(selected < 0 || !selected ? 0 : selected);

const itemToSelect = items[selected];
items.forEach((item) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/a11y-base/test/list-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ const runTests = (defineHelper, baseMixin) => {
[-1, -1, 0, -1].forEach((val, idx) => expect(list.items[idx].tabIndex).to.equal(val));
});

it('should have the first not disabled item focusable when selected set to -1', async () => {
list.selected = -1;
await nextUpdate(list);
[-1, -1, 0, -1].forEach((val, idx) => expect(list.items[idx].tabIndex).to.equal(val));
});

it('should set a not disabled item focusable', async () => {
list._setFocusable(3);
await nextUpdate(list);
Expand Down

0 comments on commit 35c00c6

Please sign in to comment.