From de2afb8621494b0f0f9e8fd438792d2eb30bf8b0 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Fri, 30 Apr 2021 13:52:36 +0200 Subject: [PATCH] Use :hover instead of event listeners to display edit button Signed-off-by: Marcus Eide --- plugins/shortcuts/src/ShortcutItem.test.tsx | 20 ----------- plugins/shortcuts/src/ShortcutItem.tsx | 38 +++++++++++---------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/plugins/shortcuts/src/ShortcutItem.test.tsx b/plugins/shortcuts/src/ShortcutItem.test.tsx index 219771909d..d32ec3d392 100644 --- a/plugins/shortcuts/src/ShortcutItem.test.tsx +++ b/plugins/shortcuts/src/ShortcutItem.test.tsx @@ -81,26 +81,6 @@ describe('ShortcutItem', () => { }); }); - it('displays the edit icon on hover', async () => { - render( - wrapInTestApp( - - - , - ), - ); - - fireEvent.mouseOver(screen.getByText('ST')); - await waitFor(() => { - expect(screen.getByTestId('edit')).toBeInTheDocument(); - }); - - fireEvent.mouseOut(screen.getByText('ST')); - await waitFor(() => { - expect(screen.queryByTestId('edit')).not.toBeInTheDocument(); - }); - }); - it('gets the color based on the theme', async () => { const { rerender } = render( wrapInTestApp(), diff --git a/plugins/shortcuts/src/ShortcutItem.tsx b/plugins/shortcuts/src/ShortcutItem.tsx index 3aec4bb3b4..f9868182f0 100644 --- a/plugins/shortcuts/src/ShortcutItem.tsx +++ b/plugins/shortcuts/src/ShortcutItem.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import React, { useState } from 'react'; +import React from 'react'; import { SidebarItem } from '@backstage/core'; import { IconButton, makeStyles } from '@material-ui/core'; import EditIcon from '@material-ui/icons/Edit'; @@ -24,6 +24,14 @@ import { ShortcutApi } from './api'; import { Shortcut } from './types'; const useStyles = makeStyles({ + root: { + '&:hover #edit': { + visibility: 'visible', + }, + }, + button: { + visibility: 'hidden', + }, icon: { color: 'white', fontSize: 16, @@ -50,7 +58,6 @@ type Props = { export const ShortcutItem = ({ shortcut, api }: Props) => { const classes = useStyles(); - const [displayEdit, setDisplayEdit] = useState(false); const [anchorEl, setAnchorEl] = React.useState(); const handleClick = (event: React.MouseEvent) => { @@ -60,32 +67,27 @@ export const ShortcutItem = ({ shortcut, api }: Props) => { const handleClose = () => { setAnchorEl(undefined); - setDisplayEdit(false); - }; - - const handleMouseEnter = () => { - setDisplayEdit(true); - }; - - const handleMouseLeave = () => { - setDisplayEdit(false); }; const text = getIconText(shortcut.title); const color = api.getColor(shortcut.url); return ( -
+ <> } > - {displayEdit && ( - - - - )} + + + { api={api} shortcut={shortcut} /> -
+ ); };