diff --git a/packages/react-core/src/components/Truncate/Truncate.tsx b/packages/react-core/src/components/Truncate/Truncate.tsx index 46bf057557a..359950c8b51 100644 --- a/packages/react-core/src/components/Truncate/Truncate.tsx +++ b/packages/react-core/src/components/Truncate/Truncate.tsx @@ -44,7 +44,8 @@ interface TruncateProps extends React.HTMLProps { | 'right-end'; } -const sliceContent = (str: string, slice: number) => [str.slice(0, str.length - slice), str.slice(-slice)]; +const sliceContent = (str: string, slice: number) => + str.length > slice ? [str.slice(0, str.length - slice), str.slice(-slice)] : str; export const Truncate: React.FunctionComponent = ({ className, @@ -88,7 +89,7 @@ export const Truncate: React.FunctionComponent = ({ if (subParentRef && subParentRef.current.parentElement.parentElement && !parentElement) { setParentElement(subParentRef.current.parentElement.parentElement); } - }, [textRef, subParentRef]); + }, [textRef, subParentRef, textElement, parentElement]); React.useEffect(() => { if (textElement && parentElement && !observer.current) { @@ -106,7 +107,7 @@ export const Truncate: React.FunctionComponent = ({ observer(); }; } - }, [textElement, parentElement]); + }, [textElement, parentElement, trailingNumChars, content, position]); const truncateBody = (