Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6dbdad2

Browse files
fix: lang selector keyboard accessibility (#2927)
Co-authored-by: Claudio Wunder <cwunder@gnome.org>
1 parent 4dbac77 commit 6dbdad2

11 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/components/CommonComponents/Dropdown/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ const Dropdown = <T extends HTMLElement>({
2424
fontWeight: (item.active ? 'bold' : 'normal') as 'bold' | 'normal',
2525
};
2626

27+
const handleKeyPress = (e: React.KeyboardEvent<HTMLButtonElement>) => {
28+
if (e.key === 'Enter' || e.key === ' ') {
29+
item.onClick();
30+
}
31+
};
32+
2733
return (
2834
<li key={`dropdown-item-${item.label}`}>
2935
<button
3036
style={extraStyles}
3137
onClick={item.onClick}
32-
onKeyDown={item.onClick}
38+
onKeyDown={handleKeyPress}
3339
type="button"
3440
>
3541
{item.title}

src/components/CommonComponents/LanguageSelector/__tests__/__snapshots__/LanguageSelector.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`LanguageSelector component renders correctly 1`] = `
44
<div>
55
<button
6+
aria-expanded="false"
67
class="languageSwitch"
78
type="button"
89
>

src/components/CommonComponents/LanguageSelector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const LanguageSelector = () => {
2121
className={styles.languageSwitch}
2222
ref={languageButtonRef}
2323
onClick={() => showDropdown(!visible)}
24+
aria-expanded={visible}
2425
>
2526
<span className="sr-only">Switch Language</span>
2627
<TranslateIcon />

src/layouts/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`Layout component renders correctly with data 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>

src/layouts/__tests__/__snapshots__/page.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`PageLayout component renders correctly with data 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>

src/pages/about/__tests__/__snapshots__/resources.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`Resources page renders correctly 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>

src/pages/download/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`Download page renders correctly 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>
@@ -1144,6 +1145,7 @@ exports[`Download page should handle LTS to Current switch 1`] = `
11441145
</li>
11451146
<li>
11461147
<button
1148+
aria-expanded="false"
11471149
class="languageSwitch"
11481150
type="button"
11491151
>

src/pages/download/__tests__/__snapshots__/package-manager.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`Package Manager Page renders correctly 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>

src/sections/Header/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ exports[`Tests for Header component Theme color switcher skips rendering in case
155155
</li>
156156
<li>
157157
<button
158+
aria-expanded="false"
158159
class="languageSwitch"
159160
type="button"
160161
>
@@ -389,6 +390,7 @@ exports[`Tests for Header component renders correctly 1`] = `
389390
</li>
390391
<li>
391392
<button
393+
aria-expanded="false"
392394
class="languageSwitch"
393395
type="button"
394396
>
@@ -623,6 +625,7 @@ exports[`Tests for Header component renders shorter menu items for mobile 1`] =
623625
</li>
624626
<li>
625627
<button
628+
aria-expanded="false"
626629
class="languageSwitch"
627630
type="button"
628631
>

src/templates/__tests__/__snapshots__/learn.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ exports[`Learn Template renders correctly 1`] = `
158158
</li>
159159
<li>
160160
<button
161+
aria-expanded="false"
161162
class="languageSwitch"
162163
type="button"
163164
>

0 commit comments

Comments
 (0)