Skip to content

Commit

Permalink
fix(components): stop bubbling for processed a11y arrow key events
Browse files Browse the repository at this point in the history
  • Loading branch information
CoroDaniel authored and cipak committed Mar 22, 2022
1 parent 615fdff commit 85c5738
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/WebexSettings/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ export default function Tabs({

const handleKeyUp = (event) => {
if (event.key === 'ArrowLeft') {
event.stopPropagation(); // prevent other navigation
const prevTabIndex = (selectedTabIndex + tabs.length - 1) % tabs.length;

setTabChangedWithKey(true);
onSelect(tabs[prevTabIndex].key);
} else if (event.key === 'ArrowRight') {
event.stopPropagation(); // prevent other navigation
const nextTabIndex = (selectedTabIndex + 1) % tabs.length;

setTabChangedWithKey(true);
Expand Down
2 changes: 2 additions & 0 deletions src/components/generic/OptionsList/Option.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export default function Option({

if (event.key === 'ArrowUp') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.previousElementSibling;
} else if (event.key === 'ArrowDown') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.nextElementSibling;
} else if (event.key === 'Enter') {
onSelect(option, true);
Expand Down
2 changes: 2 additions & 0 deletions src/components/inputs/Checkbox/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export default function Checkbox({
onChange(!selected);
} else if (event.key === 'ArrowUp') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.previousElementSibling;
} else if (event.key === 'ArrowDown') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.nextElementSibling;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/inputs/Dropdown/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function Dropdown({
collapse();
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
expand(true);
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/inputs/RadioButton/RadioButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export default function RadioButton({
onChange(!selected);
} else if (event.key === 'ArrowUp') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.previousElementSibling;
} else if (event.key === 'ArrowDown') {
event.preventDefault(); // prevent page scrolling
event.stopPropagation(); // prevent other navigation
toFocus = ref.current.nextElementSibling;
}

Expand Down

0 comments on commit 85c5738

Please sign in to comment.