Skip to content

Commit cfb8b4d

Browse files
committed
fix(Progress): enable truncated tooltip via keyboard
1 parent c1321c8 commit cfb8b4d

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

packages/react-core/src/components/Progress/ProgressContainer.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useState } from 'react';
1+
import { Fragment, useState, useRef, useEffect } from 'react';
22
import progressStyle from '@patternfly/react-styles/css/components/Progress/progress';
33
import { css } from '@patternfly/react-styles';
44
import { Tooltip, TooltipPosition } from '../Tooltip';
@@ -80,13 +80,21 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
8080
}: ProgressContainerProps) => {
8181
const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
8282
const [tooltip, setTooltip] = useState('');
83-
const onMouseEnter = (event: any) => {
83+
const titleRef = useRef(null);
84+
const onFocus = (event: any) => {
8485
if (event.target.offsetWidth < event.target.scrollWidth) {
8586
setTooltip(title || event.target.innerHTML);
8687
} else {
8788
setTooltip('');
8889
}
8990
};
91+
92+
useEffect(() => {
93+
if (tooltip !== '') {
94+
titleRef.current.focus();
95+
}
96+
}, [tooltip]);
97+
9098
const Title = (
9199
<div
92100
className={css(
@@ -95,22 +103,23 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
95103
)}
96104
id={`${parentId}-description`}
97105
aria-hidden="true"
98-
onMouseEnter={isTitleTruncated && typeof title === 'string' ? onMouseEnter : null}
106+
onMouseEnter={isTitleTruncated && typeof title === 'string' ? onFocus : null}
107+
onFocus={isTitleTruncated && typeof title === 'string' ? onFocus : null}
108+
{...(isTitleTruncated && typeof title === 'string' && { tabIndex: 0 })}
109+
ref={titleRef}
99110
>
100111
{title}
101112
</div>
102113
);
103114

104115
return (
105116
<Fragment>
106-
{title &&
107-
(tooltip ? (
108-
<Tooltip position={tooltipPosition} content={tooltip} isVisible>
109-
{Title}
110-
</Tooltip>
111-
) : (
112-
Title
113-
))}
117+
{title && (
118+
<>
119+
{tooltip && <Tooltip position={tooltipPosition} content={tooltip} isVisible triggerRef={titleRef} />}
120+
{Title}
121+
</>
122+
)}
114123
{(measureLocation !== ProgressMeasureLocation.none || StatusIcon) && (
115124
<div className={css(progressStyle.progressStatus)} aria-hidden="true">
116125
{(measureLocation === ProgressMeasureLocation.top || measureLocation === ProgressMeasureLocation.outside) && (

0 commit comments

Comments
 (0)