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: support non-latin chars in list-mixin keyboard search (#6798) (CP: 24.2) #6799

Merged
merged 1 commit into from
Nov 16, 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
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