Skip to content

Commit

Permalink
Update to autofocus on content navigation instead of first form element
Browse files Browse the repository at this point in the history
  • Loading branch information
nealfennimore committed Dec 7, 2024
1 parent a3b6deb commit b1bfaa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 14 additions & 0 deletions client/src/app/components/content_navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"use client";
import { ElementWrapper } from "@/api/entities/Framework";
import Link from "next/link";
import { useEffect, useRef } from "react";

interface PageNavigationProps {
previous?: ElementWrapper | undefined;
next?: ElementWrapper | undefined;
}

export const ContentNavigation = ({ previous, next }: PageNavigationProps) => {
const previousRef = useRef<HTMLAnchorElement>(null);
const nextRef = useRef<HTMLAnchorElement>(null);

let nextClasses = "rounded-r-lg rounded-l-lg";
if (previous) {
nextClasses = "rounded-r-lg";
Expand All @@ -17,13 +21,22 @@ export const ContentNavigation = ({ previous, next }: PageNavigationProps) => {
prevClasses = "rounded-l-lg border-r";
}

useEffect(() => {
if (nextRef.current) {
nextRef.current.focus();
} else if (previousRef.current) {
previousRef.current.focus();
}
}, [previousRef, nextRef]);

return (
<aside className="w-5/6 flex flex-row mb-4">
{previous && (
<Link
href={`/r3/requirement/${previous.requirement}`}
className={`flex flex-row items-center bg-gray-200 text-gray-700 border-gray-400 py-2 px-4 border-b-4 hover:bg-gray-300 ${prevClasses}`}
tabIndex={10}
ref={previousRef}
>
<svg
className="w-6 h-6 text-gray-500"
Expand All @@ -49,6 +62,7 @@ export const ContentNavigation = ({ previous, next }: PageNavigationProps) => {
href={`/r3/requirement/${next.requirement}`}
className={`flex flex-row items-center bg-gray-200 text-gray-700 border-gray-400 py-2 px-4 border-b-4 hover:bg-gray-300 ${nextClasses}`}
tabIndex={11}
ref={nextRef}
>
<span className="ml-4 mr-2">
{next.requirement}: {next.title}
Expand Down
1 change: 0 additions & 1 deletion client/src/app/components/security_requirements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const Select = ({ id, defaultValue, isPending, idx }) => {
disabled={isPending}
defaultValue={defaultValue}
tabIndex={20}
autoFocus={idx === 0 && !hasChanged}
>
<option value="not-implemented">Not Implemented</option>
<option value="implemented">Implemented</option>
Expand Down

0 comments on commit b1bfaa7

Please sign in to comment.