My website features a simple table that displays devices and their characteristics. A condensed version of the table can be found in the link below.
import "./styles.css";
import { SubMenu } from "./SubMenu";
const subMenuSlice = <SubMenu />;
const nodes = [
{
id: "0",
name: "Samsung Galaxy",
subMenu: subMenuSlice
},
{
id: "0",
name: "Iphone",
subMenu: subMenuSlice
}
];
export default function App() {
return (
<table>
<tbody>
{nodes.map((val, key) => (
<tr key={key}>
<td>{val.name}</td>
<td>{val.subMenu}</td>
</tr>
))}
</tbody>
</table>
);
}
SubMenu.tsx
import { useState } from "react";
import AppsIcon from "@mui/icons-material/Apps";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import "./styles.css";
export const SubMenu = () => {
const [isOpen, setIsOpen] = useState(false);
return (
<DropdownMenu.Root open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenu.Trigger>
<AppsIcon className="sss" />
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content
side="bottom"
sideOffset={-30}
align="start"
alignOffset={80}
>
<button className="style-button">Edit </button>
<button className="style-button">Make </button>
<button className="style-button">Delete </button>
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
);
};
styles.css
.sss {
visibility: hidden;
}
tr:hover .sss {
background: gray;
visibility: visible;
}
tr:hover {
background: gray;
visibility: visible;
pointer-events: initial !important;
}
.style-button:hover {
background-color: aqua;
}
https://codesandbox.io/s/romantic-rgb-5t7xkq
When hovering over a row in the table, it turns gray and reveals an additional button. Clicking on this button opens a submenu for the user.
The issue at hand is that when the cursor moves to the submenu, the hover effect (gray) disappears from the table row. Any suggestions on how to maintain the hover effect while the submenu is active (open)?