From 2ea01f07fe3394af5763e678e455c0a82868479b Mon Sep 17 00:00:00 2001 From: Prozilla Date: Mon, 7 Aug 2023 17:28:05 +0200 Subject: [PATCH] Fixed dropdown buttons tab index --- src/components/utils/DropdownButton.jsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/utils/DropdownButton.jsx b/src/components/utils/DropdownButton.jsx index d37f60b..7d0019c 100644 --- a/src/components/utils/DropdownButton.jsx +++ b/src/components/utils/DropdownButton.jsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import styles from "./DropdownButton.module.css"; import OutsideClickListener from "../../hooks/utils/outsideClick.js"; import { formatShortcut } from "../../features/utils/string.js"; @@ -11,10 +11,11 @@ import { formatShortcut } from "../../features/utils/string.js"; */ export function DropdownButton({ label, options, shortcuts }) { const [open, setOpen] = useState(false); + const [tabIndex, setTabIndex] = useState(-1); - const tabIndex = () => { - return open ? 0 : -1; - }; + useEffect(() => { + setTabIndex(open ? 0 : -1); + }, [open]); return ( { setOpen(false); }}>