Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line breaks in tooltips & text #8783

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const StyledLabelAndIconContainer = styled.div`
color: ${({ theme }) => theme.font.color.tertiary};
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
height: 24px;
height: 18px;
padding-top: 3px;
`;

const StyledValueContainer = styled.div`
Expand All @@ -61,7 +62,7 @@ const StyledInlineCellBaseContainer = styled.div`
width: 100%;
display: flex;
height: fit-content;
line-height: 24px;
line-height: 18px;
gap: ${({ theme }) => theme.spacing(1)};
user-select: none;
justify-content: center;
Expand Down Expand Up @@ -131,11 +132,7 @@ export const RecordInlineCellContainer = () => {
)}
{showLabel && label && (
<StyledLabelContainer width={labelWidth}>
<OverflowingTextWithTooltip
text={label}
isLabel={true}
displayedMaxRows={1}
/>
<OverflowingTextWithTooltip text={label} displayedMaxRows={1} />
</StyledLabelContainer>
)}
{/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ const StyledRecordInlineCellNormalModeInnerContainer = styled.div`
align-content: center;
align-items: center;
color: ${({ theme }) => theme.font.color.primary};
font-size: 'inherit';

font-weight: 'inherit';
padding-top: 3px;
padding-bottom: 3px;

height: fit-content;

min-height: 24px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const RecordInlineCellEditMode = ({
crossAxis: 0,
}
: {
mainAxis: -28,
mainAxis: -29,
crossAxis: -4,
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const RecordTableCellEditMode = ({
middleware: [
flip(),
offset({
mainAxis: -32,
crossAxis: 0,
mainAxis: -31,
crossAxis: -2,
}),
],
whileElementsMounted: autoUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ type TextDisplayProps = {
};

export const TextDisplay = ({ text, displayedMaxRows }: TextDisplayProps) => (
<OverflowingTextWithTooltip text={text} displayedMaxRows={displayedMaxRows} />
<OverflowingTextWithTooltip
text={text}
displayedMaxRows={displayedMaxRows}
isTooltipMultiline={true}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ const StyledTextArea = styled(TextareaAutosize)`
max-height: 400px;
width: calc(100% - ${({ theme }) => theme.spacing(7)});
background: transparent;
line-height: 18px;
`;

const StyledTextAreaContainer = styled.div`
background: ${({ theme }) => theme.background.primary};
border: ${({ theme }) => `1px solid ${theme.border.color.medium}`};
position: relative;
width: 100%;
padding: ${({ theme }) => theme.spacing(2)} ${({ theme }) => theme.spacing(0)};
padding-top: ${({ theme }) => theme.spacing(2)};
padding-bottom: ${({ theme }) => theme.spacing(2)};

border-radius: ${({ theme }) => theme.border.radius.sm};

@supports (
Expand All @@ -56,7 +59,7 @@ const StyledTextAreaContainer = styled.div`
const StyledLightIconButtonContainer = styled.div`
background: transparent;
position: absolute;
top: 50%;
top: 18px;
transform: translateY(-50%);
right: 0;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const StyledOverflowingText = styled.div<{
cursorPointer: boolean;
size: 'large' | 'small';
displayedMaxRows?: number;
isLabel: boolean;
allowDisplayWrap?: boolean;
}>`
cursor: ${({ cursorPointer }) => (cursorPointer ? 'pointer' : 'inherit')};
font-family: inherit;
Expand All @@ -25,7 +23,7 @@ const StyledOverflowingText = styled.div<{
text-decoration: inherit;

text-overflow: ellipsis;

white-space: pre-wrap;
height: ${({ size }) => (size === 'large' ? spacing4 : 'auto')};

text-wrap: wrap;
Expand All @@ -42,20 +40,21 @@ const StyledOverflowingText = styled.div<{
}
`;

const Styledpre = styled.pre`
font-family: inherit;
white-space: pre-wrap;
`;

export const OverflowingTextWithTooltip = ({
size = 'small',
text,
isTooltipMultiline,
displayedMaxRows,
isLabel,
allowDisplayWrap,
}: {
size?: 'large' | 'small';
text: string | null | undefined;
isTooltipMultiline?: boolean;
displayedMaxRows?: number;
isLabel?: boolean;
allowDisplayWrap?: boolean;
}) => {
const textElementId = `title-id-${+new Date()}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using timestamp for ID generation can cause duplicate IDs if multiple tooltips are created in the same millisecond. Consider using a more reliable unique ID generation method.


Expand All @@ -81,16 +80,13 @@ export const OverflowingTextWithTooltip = ({
event.stopPropagation();
event.preventDefault();
};

return (
<>
<StyledOverflowingText
data-testid="tooltip"
cursorPointer={isTitleOverflowing}
size={size}
displayedMaxRows={displayedMaxRows}
allowDisplayWrap={allowDisplayWrap}
isLabel={isLabel ?? false}
ref={textRef}
id={textElementId}
onMouseEnter={handleMouseEnter}
Expand All @@ -103,15 +99,18 @@ export const OverflowingTextWithTooltip = ({
<div onClick={handleTooltipClick}>
<AppTooltip
anchorSelect={`#${textElementId}`}
content={isTooltipMultiline ? undefined : (text ?? '')}
offset={5}
isOpen
noArrow
place="bottom"
positionStrategy="absolute"
delay={TooltipDelay.mediumDelay}
>
{isTooltipMultiline ? <pre>{text}</pre> : ''}
{isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip>
</div>,
document.body,
Expand Down
Loading