Skip to content

Commit

Permalink
fix: only focus active elements
Browse files Browse the repository at this point in the history
  • Loading branch information
acdibble committed Sep 19, 2023
1 parent 968466f commit 6c2a1f7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/components/App.tsx
Expand Up @@ -236,7 +236,9 @@ export default class App extends PureComponent<Props, State> {

focusNext = (): void => {
this.setState(previousState => {
const firstFocusableId = previousState.focusables[0]?.id;
const firstFocusableId = previousState.focusables.find(
focusable => focusable.isActive
)?.id;
const nextFocusableId = this.findNextFocusable(previousState);

return {
Expand All @@ -247,8 +249,19 @@ export default class App extends PureComponent<Props, State> {

focusPrevious = (): void => {
this.setState(previousState => {
const lastFocusableId =
previousState.focusables[previousState.focusables.length - 1]?.id;
let lastFocusableId: string | undefined;
for (
let index = previousState.focusables.length - 1;
index >= 0;
index--
) {
const focusable = previousState.focusables[index];

if (focusable?.isActive) {
lastFocusableId = focusable.id;
break;
}
}

const previousFocusableId = this.findPreviousFocusable(previousState);

Expand Down

0 comments on commit 6c2a1f7

Please sign in to comment.