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

fix: lang selector keyboard accessibility #2927

Merged
merged 4 commits into from Oct 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/CommonComponents/Dropdown/index.tsx
Expand Up @@ -24,12 +24,18 @@ const Dropdown = <T extends HTMLElement>({
fontWeight: (item.active ? 'bold' : 'normal') as 'bold' | 'normal',
};

const handleKeyPress = (e: React.KeyboardEvent<HTMLButtonElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
ovflowd marked this conversation as resolved.
Show resolved Hide resolved
item.onClick();
}
};

return (
<li key={`dropdown-item-${item.label}`}>
<button
style={extraStyles}
onClick={item.onClick}
onKeyDown={item.onClick}
onKeyDown={handleKeyPress}
type="button"
>
{item.title}
Expand Down
Expand Up @@ -3,6 +3,7 @@
exports[`LanguageSelector component renders correctly 1`] = `
<div>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions src/components/CommonComponents/LanguageSelector/index.tsx
Expand Up @@ -21,6 +21,7 @@ const LanguageSelector = () => {
className={styles.languageSwitch}
ref={languageButtonRef}
onClick={() => showDropdown(!visible)}
aria-expanded={visible}
>
<span className="sr-only">Switch Language</span>
<TranslateIcon />
Expand Down
1 change: 1 addition & 0 deletions src/layouts/__tests__/__snapshots__/index.test.tsx.snap
Expand Up @@ -158,6 +158,7 @@ exports[`Layout component renders correctly with data 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions src/layouts/__tests__/__snapshots__/page.test.tsx.snap
Expand Up @@ -158,6 +158,7 @@ exports[`PageLayout component renders correctly with data 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
Expand Up @@ -158,6 +158,7 @@ exports[`Resources page renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
Expand Up @@ -158,6 +158,7 @@ exports[`Download page renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down Expand Up @@ -1144,6 +1145,7 @@ exports[`Download page should handle LTS to Current switch 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
Expand Up @@ -158,6 +158,7 @@ exports[`Package Manager Page renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
Expand Up @@ -155,6 +155,7 @@ exports[`Tests for Header component Theme color switcher skips rendering in case
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down Expand Up @@ -389,6 +390,7 @@ exports[`Tests for Header component renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down Expand Up @@ -623,6 +625,7 @@ exports[`Tests for Header component renders shorter menu items for mobile 1`] =
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions src/templates/__tests__/__snapshots__/learn.test.tsx.snap
Expand Up @@ -158,6 +158,7 @@ exports[`Learn Template renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions src/templates/__tests__/__snapshots__/post.test.tsx.snap
Expand Up @@ -158,6 +158,7 @@ exports[`LearnLayout Template renders correctly 1`] = `
</li>
<li>
<button
aria-expanded="false"
class="languageSwitch"
type="button"
>
Expand Down