visual indicator
This commit is contained in:
1 parent
9a8799f964
commit
7e07f01724
1 file changed
+26
-3
@@ -1,3 +1,4 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
@@ -14,10 +15,10 @@ import "./index.css";
|
|||||||
* @param {string} [props.open] - Specifies the initially open tab: 'profile', 'password', or 'team'.
|
* @param {string} [props.open] - Specifies the initially open tab: 'profile', 'password', or 'team'.
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Account = ({ open = "profile" }) => {
|
const Account = ({ open = "profile" }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [focusedTab, setFocusedTab] = useState(null); // Track focused tab
|
||||||
const tab = open;
|
const tab = open;
|
||||||
const handleTabChange = (event, newTab) => {
|
const handleTabChange = (event, newTab) => {
|
||||||
navigate(`/account/${newTab}`);
|
navigate(`/account/${newTab}`);
|
||||||
@@ -33,9 +34,24 @@ const Account = ({ open = "profile" }) => {
|
|||||||
|
|
||||||
// Remove password for demo
|
// Remove password for demo
|
||||||
if (user.role.includes("demo")) {
|
if (user.role.includes("demo")) {
|
||||||
tabList = ["Profile"];
|
tabList = ["Profile", "Password", "Team"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = (event) => {
|
||||||
|
const currentIndex = tabList.findIndex((label) => label.toLowerCase() === tab);
|
||||||
|
if (event.key === "Tab") {
|
||||||
|
const nextIndex = (currentIndex + 1) % tabList.length;
|
||||||
|
setFocusedTab(tabList[nextIndex].toLowerCase());
|
||||||
|
} else if (event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
navigate(`/account/${focusedTab}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFocus = (tabName) => {
|
||||||
|
setFocusedTab(tabName);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="account"
|
className="account"
|
||||||
@@ -63,6 +79,9 @@ const Account = ({ open = "profile" }) => {
|
|||||||
label={label}
|
label={label}
|
||||||
key={index}
|
key={index}
|
||||||
value={label.toLowerCase()}
|
value={label.toLowerCase()}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
onFocus={() => handleFocus(label.toLowerCase())}
|
||||||
|
tabIndex={index}
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: theme.palette.text.tertiary,
|
color: theme.palette.text.tertiary,
|
||||||
@@ -74,7 +93,11 @@ const Account = ({ open = "profile" }) => {
|
|||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
marginRight: theme.spacing(8),
|
marginRight: theme.spacing(8),
|
||||||
"&:focus": {
|
"&:focus": {
|
||||||
outline: "none",
|
borderBottom: `2px solid ${theme.palette.border.light}`,
|
||||||
|
},
|
||||||
|
|
||||||
|
"&:hover": {
|
||||||
|
borderBottom: `2px solid ${theme.palette.border.light}`,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user