Fix Table text wrapping (#8683)
As discovered during the last release, text fields in the table were wrapped. This PR fixes this unwanted behaviour Current : <img width="1077" alt="Screenshot 2024-11-22 at 14 17 42" src="https://github.com/user-attachments/assets/080c5b1f-b793-46de-8733-9c69a4eb6b3b"> Wanted : One line ellipsed <img width="244" alt="Screenshot 2024-11-22 at 14 20 46" src="https://github.com/user-attachments/assets/c1d32859-4ffe-42e3-bfed-66db20c8c0c7"> --------- Co-authored-by: guillim <guillaume@twenty.com>
This commit is contained in:
@ -31,6 +31,7 @@ export type GenericFieldContextType = {
|
|||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
isCentered?: boolean;
|
isCentered?: boolean;
|
||||||
overridenIsFieldEmpty?: boolean;
|
overridenIsFieldEmpty?: boolean;
|
||||||
|
displayedMaxRows?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FieldContext = createContext<GenericFieldContextType>(
|
export const FieldContext = createContext<GenericFieldContextType>(
|
||||||
|
|||||||
@ -3,11 +3,19 @@ import { isFieldText } from '@/object-record/record-field/types/guards/isFieldTe
|
|||||||
import { TextDisplay } from '@/ui/field/display/components/TextDisplay';
|
import { TextDisplay } from '@/ui/field/display/components/TextDisplay';
|
||||||
|
|
||||||
export const TextFieldDisplay = () => {
|
export const TextFieldDisplay = () => {
|
||||||
const { fieldValue, fieldDefinition } = useTextFieldDisplay();
|
const { fieldValue, fieldDefinition, displayedMaxRows } =
|
||||||
|
useTextFieldDisplay();
|
||||||
|
|
||||||
const displayedMaxRows = isFieldText(fieldDefinition)
|
const displayedMaxRowsFromSettings = isFieldText(fieldDefinition)
|
||||||
? fieldDefinition.metadata?.settings?.displayedMaxRows
|
? fieldDefinition.metadata?.settings?.displayedMaxRows
|
||||||
: 1;
|
: undefined;
|
||||||
|
|
||||||
return <TextDisplay text={fieldValue} displayedMaxRows={displayedMaxRows} />;
|
return (
|
||||||
|
<TextDisplay
|
||||||
|
text={fieldValue}
|
||||||
|
displayedMaxRows={
|
||||||
|
displayedMaxRows ? displayedMaxRows : displayedMaxRowsFromSettings
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,8 @@ import { useRecordFieldValue } from '@/object-record/record-store/contexts/Recor
|
|||||||
import { FieldContext } from '../../contexts/FieldContext';
|
import { FieldContext } from '../../contexts/FieldContext';
|
||||||
|
|
||||||
export const useTextFieldDisplay = () => {
|
export const useTextFieldDisplay = () => {
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
const { recordId, fieldDefinition, hotkeyScope, displayedMaxRows } =
|
||||||
|
useContext(FieldContext);
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
const fieldName = fieldDefinition.metadata.fieldName;
|
||||||
|
|
||||||
@ -16,5 +17,6 @@ export const useTextFieldDisplay = () => {
|
|||||||
fieldDefinition,
|
fieldDefinition,
|
||||||
fieldValue,
|
fieldValue,
|
||||||
hotkeyScope,
|
hotkeyScope,
|
||||||
|
displayedMaxRows,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -131,7 +131,11 @@ export const RecordInlineCellContainer = () => {
|
|||||||
)}
|
)}
|
||||||
{showLabel && label && (
|
{showLabel && label && (
|
||||||
<StyledLabelContainer width={labelWidth}>
|
<StyledLabelContainer width={labelWidth}>
|
||||||
<OverflowingTextWithTooltip text={label} isLabel={true} />
|
<OverflowingTextWithTooltip
|
||||||
|
text={label}
|
||||||
|
isLabel={true}
|
||||||
|
displayedMaxRows={1}
|
||||||
|
/>
|
||||||
</StyledLabelContainer>
|
</StyledLabelContainer>
|
||||||
)}
|
)}
|
||||||
{/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */}
|
{/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */}
|
||||||
|
|||||||
@ -50,6 +50,7 @@ export const RecordTableCellFieldContextWrapper = ({
|
|||||||
},
|
},
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
}),
|
}),
|
||||||
|
displayedMaxRows: 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const StyledOverflowingText = styled.div<{
|
|||||||
size: 'large' | 'small';
|
size: 'large' | 'small';
|
||||||
displayedMaxRows?: number;
|
displayedMaxRows?: number;
|
||||||
isLabel: boolean;
|
isLabel: boolean;
|
||||||
|
allowDisplayWrap?: boolean;
|
||||||
}>`
|
}>`
|
||||||
cursor: ${({ cursorPointer }) => (cursorPointer ? 'pointer' : 'inherit')};
|
cursor: ${({ cursorPointer }) => (cursorPointer ? 'pointer' : 'inherit')};
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
@ -24,18 +25,14 @@ const StyledOverflowingText = styled.div<{
|
|||||||
text-decoration: inherit;
|
text-decoration: inherit;
|
||||||
|
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
|
||||||
|
|
||||||
height: ${({ size }) => (size === 'large' ? spacing4 : 'auto')};
|
height: ${({ size }) => (size === 'large' ? spacing4 : 'auto')};
|
||||||
|
|
||||||
text-wrap-mode: ${({ isLabel, displayedMaxRows }) =>
|
text-wrap: wrap;
|
||||||
isLabel === false && displayedMaxRows ? 'wrap' : 'nowrap'};
|
-webkit-line-clamp: ${({ displayedMaxRows }) =>
|
||||||
-webkit-line-clamp: ${({ isLabel, displayedMaxRows }) =>
|
displayedMaxRows ? displayedMaxRows : '1'};
|
||||||
isLabel === false && displayedMaxRows ? displayedMaxRows : 'inherit'};
|
display: -webkit-box;
|
||||||
display: ${({ isLabel, displayedMaxRows }) =>
|
-webkit-box-orient: vertical;
|
||||||
isLabel === false && displayedMaxRows ? `-webkit-box` : 'block'};
|
|
||||||
-webkit-box-orient: ${({ isLabel, displayedMaxRows }) =>
|
|
||||||
isLabel === false && displayedMaxRows ? 'vertical' : 'inherit'};
|
|
||||||
|
|
||||||
& :hover {
|
& :hover {
|
||||||
text-overflow: ${({ cursorPointer }) =>
|
text-overflow: ${({ cursorPointer }) =>
|
||||||
@ -51,12 +48,14 @@ export const OverflowingTextWithTooltip = ({
|
|||||||
isTooltipMultiline,
|
isTooltipMultiline,
|
||||||
displayedMaxRows,
|
displayedMaxRows,
|
||||||
isLabel,
|
isLabel,
|
||||||
|
allowDisplayWrap,
|
||||||
}: {
|
}: {
|
||||||
size?: 'large' | 'small';
|
size?: 'large' | 'small';
|
||||||
text: string | null | undefined;
|
text: string | null | undefined;
|
||||||
isTooltipMultiline?: boolean;
|
isTooltipMultiline?: boolean;
|
||||||
displayedMaxRows?: number;
|
displayedMaxRows?: number;
|
||||||
isLabel?: boolean;
|
isLabel?: boolean;
|
||||||
|
allowDisplayWrap?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const textElementId = `title-id-${+new Date()}`;
|
const textElementId = `title-id-${+new Date()}`;
|
||||||
|
|
||||||
@ -90,6 +89,7 @@ export const OverflowingTextWithTooltip = ({
|
|||||||
cursorPointer={isTitleOverflowing}
|
cursorPointer={isTitleOverflowing}
|
||||||
size={size}
|
size={size}
|
||||||
displayedMaxRows={displayedMaxRows}
|
displayedMaxRows={displayedMaxRows}
|
||||||
|
allowDisplayWrap={allowDisplayWrap}
|
||||||
isLabel={isLabel ?? false}
|
isLabel={isLabel ?? false}
|
||||||
ref={textRef}
|
ref={textRef}
|
||||||
id={textElementId}
|
id={textElementId}
|
||||||
|
|||||||
Reference in New Issue
Block a user