Fix accessibility issues

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-04-08 07:50:55 -07:00
parent e8dacef374
commit 19bd741188

View File

@@ -7,7 +7,7 @@ import {
useMutation, useMutation,
ConnectionHandler, ConnectionHandler,
} from "react-relay"; } from "react-relay";
import { useParams, useNavigate, Link } from "react-router"; import { useParams, Link } from "react-router";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { import {
ChevronRight, ChevronRight,
@@ -115,7 +115,6 @@ function MitigationListContent({
queryRef queryRef
) as unknown as OrganizationData; ) as unknown as OrganizationData;
const navigate = useNavigate();
const { organizationId } = useParams(); const { organizationId } = useParams();
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const [isImporting, setIsImporting] = useState(false); const [isImporting, setIsImporting] = useState(false);
@@ -127,29 +126,26 @@ function MitigationListContent({
); );
// Monitor URL hash for changes and update state accordingly // Monitor URL hash for changes and update state accordingly
const [hashValue, setHashValue] = useState(window.location.hash); const [initialHashCategory] = useState(() =>
window.location.hash.substring(1)
// Get the active category from the hash ? decodeURIComponent(window.location.hash.substring(1))
const hashCategory = hashValue.substring(1) : ""
? decodeURIComponent(hashValue.substring(1)) );
: "";
// Keep track of manually expanded categories // Keep track of manually expanded categories
const [expandedCategories, setExpandedCategories] = useState<string[]>(() => { const [expandedCategories, setExpandedCategories] = useState<string[]>(() => {
return hashCategory ? [hashCategory] : []; return initialHashCategory ? [initialHashCategory] : [];
}); });
// When hash changes, update expanded categories to include the hash category
useEffect(() => {
if (hashCategory && !expandedCategories.includes(hashCategory)) {
setExpandedCategories((prev) => [...prev, hashCategory]);
}
}, [hashCategory, expandedCategories]);
// Listen for hash changes (like when using back button) // Listen for hash changes (like when using back button)
useEffect(() => { useEffect(() => {
const handleHashChange = () => { const handleHashChange = () => {
setHashValue(window.location.hash); const newHash = window.location.hash.substring(1)
? decodeURIComponent(window.location.hash.substring(1))
: "";
if (newHash && !expandedCategories.includes(newHash)) {
setExpandedCategories((prev) => [...prev, newHash]);
}
}; };
window.addEventListener("hashchange", handleHashChange); window.addEventListener("hashchange", handleHashChange);
@@ -157,7 +153,7 @@ function MitigationListContent({
return () => { return () => {
window.removeEventListener("hashchange", handleHashChange); window.removeEventListener("hashchange", handleHashChange);
}; };
}, []); }, [expandedCategories]);
const mitigations = const mitigations =
data.organization.mitigations?.edges.map((edge) => edge.node) ?? []; data.organization.mitigations?.edges.map((edge) => edge.node) ?? [];
@@ -519,33 +515,6 @@ function MitigationListContent({
<tr <tr
key={mitigation.id || Math.random().toString()} key={mitigation.id || Math.random().toString()}
className="hover:bg-h-subtle-bg cursor-pointer" className="hover:bg-h-subtle-bg cursor-pointer"
onClick={() => {
if (mitigation?.id) {
// Store this category in the hash
const encoded = encodeURIComponent(
category.id
);
window.location.hash = encoded;
setHashValue("#" + encoded);
// Make sure this category is expanded in the local state
if (
!expandedCategories.includes(category.id)
) {
setExpandedCategories((prev) => [
...prev,
category.id,
]);
}
// Use a small timeout to ensure the hash change is processed
setTimeout(() => {
navigate(
`/organizations/${organizationId}/mitigations/${mitigation.id}`
);
}, 100);
}
}}
> >
<td className="w-24 px-4 py-3 align-middle"> <td className="w-24 px-4 py-3 align-middle">
<Badge variant="outline" className="text-xs"> <Badge variant="outline" className="text-xs">
@@ -560,9 +529,12 @@ function MitigationListContent({
</div> </div>
</td> </td>
<td className="px-4 py-3 align-middle"> <td className="px-4 py-3 align-middle">
<div className="font-medium"> <Link
to={`/organizations/${organizationId}/mitigations/${mitigation.id}`}
className="font-medium block"
>
{mitigation.name} {mitigation.name}
</div> </Link>
</td> </td>
</tr> </tr>
))} ))}