Skip to content

Commit

Permalink
adding some delay for tooltip (#9339)
Browse files Browse the repository at this point in the history
tooltips are currently instantaneous. let's add some delay for better
user experience

After investigation, it looks like the open property prevents delays
from happening. Swithcing to hidden property

See https://discord.com/channels/1130383047699738754/1324678408684306486
  • Loading branch information
guillim authored Jan 3, 2025
1 parent 5bd2154 commit a0fe94d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { useInlineCell } from '@/object-record/record-inline-cell/hooks/useInlineCell';
import { OverflowingTextWithTooltip } from 'twenty-ui';

type TextDisplayProps = {
text: string;
displayedMaxRows?: number;
};

export const TextDisplay = ({ text, displayedMaxRows }: TextDisplayProps) => (
<OverflowingTextWithTooltip
text={text}
displayedMaxRows={displayedMaxRows}
isTooltipMultiline={true}
/>
);
export const TextDisplay = ({ text, displayedMaxRows }: TextDisplayProps) => {
const { isInlineCellInEditMode } = useInlineCell();
return (
<OverflowingTextWithTooltip
text={text}
displayedMaxRows={displayedMaxRows}
isTooltipMultiline={true}
hideTooltip={isInlineCellInEditMode}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const ViewFieldsVisibilityDropdownSection = ({
}-item-tooltip-anchor-${openToolTipIndex}`}
place="left"
content={fields[openToolTipIndex].infoTooltipContent}
isOpen={true}
hidden={false}
/>,
document.body,
)}
Expand Down
10 changes: 5 additions & 5 deletions packages/twenty-ui/src/display/tooltip/AppTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlacesType, PositionStrategy, Tooltip } from 'react-tooltip';
import styled from '@emotion/styled';
import { PlacesType, PositionStrategy, Tooltip } from 'react-tooltip';

import { RGBA } from '@ui/theme/constants/Rgba';

Expand Down Expand Up @@ -44,7 +44,7 @@ export type AppTooltipProps = {
children?: React.ReactNode;
offset?: number;
noArrow?: boolean;
isOpen?: boolean;
hidden?: boolean;
place?: PlacesType;
delay?: TooltipDelay;
positionStrategy?: PositionStrategy;
Expand All @@ -55,7 +55,7 @@ export const AppTooltip = ({
anchorSelect,
className,
content,
isOpen,
hidden = false,
noArrow,
offset,
delay = TooltipDelay.mediumDelay,
Expand All @@ -78,8 +78,8 @@ export const AppTooltip = ({
className,
content,
delayShow: delayInMs,
delayHide: delayInMs,
isOpen,
delayHide: 20,
hidden,
noArrow,
offset,
place,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ export const OverflowingTextWithTooltip = ({
text,
isTooltipMultiline,
displayedMaxRows,
hideTooltip,
}: {
size?: 'large' | 'small';
text: string | null | undefined;
isTooltipMultiline?: boolean;
displayedMaxRows?: number;
hideTooltip?: boolean;
}) => {
const textElementId = `title-id-${+new Date()}`;

Expand Down Expand Up @@ -135,27 +137,26 @@ export const OverflowingTextWithTooltip = ({
{text}
</StyledOverflowingText>
)}
{isTitleOverflowing &&
createPortal(
<div onClick={handleTooltipClick}>
<AppTooltip
anchorSelect={`#${textElementId}`}
offset={5}
isOpen
noArrow
place="bottom"
positionStrategy="absolute"
delay={TooltipDelay.mediumDelay}
>
{isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip>
</div>,
document.body,
)}
{createPortal(
<div onClick={handleTooltipClick}>
<AppTooltip
anchorSelect={`#${textElementId}`}
offset={5}
hidden={!isTitleOverflowing || hideTooltip}
noArrow
place="bottom"
positionStrategy="absolute"
delay={TooltipDelay.mediumDelay}
>
{isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip>
</div>,
document.body,
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Default: Story = {
place: TooltipPosition.Bottom,
delay: TooltipDelay.mediumDelay,
content: 'Tooltip Test',
isOpen: true,
hidden: false,
anchorSelect: '#hover-text',
},
decorators: [ComponentDecorator],
Expand All @@ -34,7 +34,7 @@ export const Default: Story = {
className,
content,
delay,
isOpen,
hidden,
noArrow,
offset,
place,
Expand All @@ -51,7 +51,7 @@ export const Default: Story = {
className,
content,
delay,
isOpen,
hidden,
noArrow,
offset,
place,
Expand All @@ -68,7 +68,7 @@ export const Hoverable: Story = {
place: TooltipPosition.Bottom,
delay: TooltipDelay.mediumDelay,
content: 'Tooltip Test',
isOpen: true,
hidden: false,
anchorSelect: '#hover-text',
},
decorators: [ComponentDecorator],
Expand Down Expand Up @@ -103,7 +103,7 @@ export const Hoverable: Story = {
};

export const Catalog: CatalogStory<Story, typeof Tooltip> = {
args: { isOpen: true, content: 'Tooltip Test' },
args: { hidden: false, content: 'Tooltip Test' },
play: async ({ canvasElement }) => {
Object.values(TooltipPosition).forEach((position) => {
const element = canvasElement.querySelector(
Expand Down

0 comments on commit a0fe94d

Please sign in to comment.