Skip to content

Commit

Permalink
Merge pull request twentyhq#1 from AyushAgrawal-A2/ayush/twentyhq#1826
Browse files Browse the repository at this point in the history
Fix: onMouseEnter retrigger
  • Loading branch information
Davidkramer1999 authored Oct 8, 2023
2 parents df47fb5 + cba4888 commit 47f33b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement, useContext } from 'react';
import { ReactElement, useContext, useState } from 'react';
import styled from '@emotion/styled';

import { useIsFieldEmpty } from '@/ui/field/hooks/useIsFieldEmpty';
Expand Down Expand Up @@ -58,6 +58,10 @@ export const TableCellContainer = ({
}: EditableCellProps) => {
const { isCurrentTableCellInEditMode } = useCurrentTableCellEditMode();

const [isHovered, setIsHovered] = useState(false);

const hasSoftFocus = useIsSoftFocusOnCurrentTableCell();

const setSoftFocusOnCurrentTableCell = useSetSoftFocusOnCurrentTableCell();

const { openTableCell, closeTableCell } = useTableCell();
Expand All @@ -68,21 +72,25 @@ export const TableCellContainer = ({
};

const handleContainerMouseEnter = () => {
setSoftFocusOnCurrentTableCell();
if (!isHovered) {
setIsHovered(true);
setSoftFocusOnCurrentTableCell();
}
};

const handleContainerMouseLeave = () => {
setIsHovered(false);
closeTableCell();
};

const editModeContentOnly = useIsFieldInputOnly();
const hasSoftFocus = useIsSoftFocusOnCurrentTableCell();

const isFirstColumnCell = useContext(ColumnIndexContext) === 0;

const isEmpty = useIsFieldEmpty();

const showButton =
buttonIcon &&
!!buttonIcon &&
hasSoftFocus &&
!isCurrentTableCellInEditMode &&
!editModeContentOnly &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const StyledEditableCellDisplayModeOuterContainer = styled.div<
padding-right: ${({ theme }) => theme.spacing(1)};
width: 100%;
${(props) =>
props.softFocus || props.isHovered
props.softFocus
? `background: ${props.theme.background.transparent.secondary};
border-radius: ${props.theme.border.radius.sm};
outline: 1px solid ${props.theme.font.color.extraLight};`
Expand All @@ -39,14 +39,12 @@ export const TableCellDisplayContainer = ({
softFocus,
onClick,
scrollRef,
isHovered,
}: React.PropsWithChildren<EditableCellDisplayContainerProps>) => (
<StyledEditableCellDisplayModeOuterContainer
data-testid={
softFocus ? 'editable-cell-soft-focus-mode' : 'editable-cell-display-mode'
}
onClick={onClick}
isHovered={isHovered}
softFocus={softFocus}
ref={scrollRef}
>
Expand Down

0 comments on commit 47f33b2

Please sign in to comment.