Skip to content

Commit 2cf0532

Browse files
committed
bring back resizeObserver with debounce so tabIndex updates
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
1 parent 542162b commit 2cf0532

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/react-core/src/components/Truncate/Truncate.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Fragment, useEffect, useRef, useState, forwardRef, useImperativeHandle
22
import styles from '@patternfly/react-styles/css/components/Truncate/truncate';
33
import { css } from '@patternfly/react-styles';
44
import { Tooltip, TooltipPosition, TooltipProps } from '../Tooltip';
5+
import { getResizeObserver } from '../../helpers/resizeObserver';
6+
import { debounce } from '../../helpers/util';
57

68
export enum TruncatePosition {
79
start = 'start',
@@ -111,6 +113,21 @@ const TruncateBase: React.FunctionComponent<TruncateProps> = ({
111113
}
112114
}, [shouldRenderByMaxChars, content]);
113115

116+
const debouncedHandleResize = debounce(() => {
117+
if (!shouldRenderByMaxChars && textRef.current) {
118+
const isCurrentlyTruncated = textRef.current.scrollWidth > textRef.current.clientWidth;
119+
setIsTruncated(isCurrentlyTruncated);
120+
}
121+
}, 500);
122+
123+
// Set up ResizeObserver for non-maxChars truncation
124+
useEffect(() => {
125+
if (!shouldRenderByMaxChars && textRef.current) {
126+
const observer = getResizeObserver(textRef.current, debouncedHandleResize, false);
127+
return observer;
128+
}
129+
}, [shouldRenderByMaxChars, debouncedHandleResize]);
130+
114131
// Check if content is truncated (called on hover/focus)
115132
const checkTruncation = (): boolean => {
116133
if (shouldRenderByMaxChars) {

0 commit comments

Comments
 (0)