Skip to content

Commit

Permalink
fix: support non-latin chars in list-mixin keyboard search (#6798) (#…
Browse files Browse the repository at this point in the history
…6799)

Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Nov 16, 2023
1 parent 40a04bd commit 89ab610
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/a11y-base/src/list-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const ListMixin = (superClass) =>
const key = event.key;

const currentIdx = this.items.indexOf(this.focused);
if (/[a-zA-Z0-9]/u.test(key) && key.length === 1) {
if (/[\p{L}\p{Nd}]/u.test(key) && key.length === 1) {
const idx = this._searchKey(currentIdx, key);
if (idx >= 0) {
this._focus(idx);
Expand Down
19 changes: 19 additions & 0 deletions packages/a11y-base/test/list-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,25 @@ const runTests = (defineHelper, baseMixin) => {
keyDownChar(list, 'b');
expect(list.items[1].focused).to.be.true;
});

describe('non-latin keys', () => {
const LARGE = 'ใหญ่';
const SMALL = 'เล็ก';

beforeEach(() => {
list.items[0].textContent = LARGE;
list.items[1].textContent = SMALL;
list.items[1].removeAttribute('label');
});

it('should select items when non-latin keys are pressed', () => {
keyDownChar(list, SMALL.charAt(0));
expect(list.items[1].focused).to.be.true;

keyDownChar(list, LARGE.charAt(0));
expect(list.items[0].focused).to.be.true;
});
});
});

describe('empty items', () => {
Expand Down

0 comments on commit 89ab610

Please sign in to comment.