From 79bf6e982e7091920f1400637848610acc2c10f9 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 31 Mar 2025 16:25:57 -0400 Subject: [PATCH 1/5] fix(Progress): enable truncated tooltip via keyboard --- .../components/Progress/ProgressContainer.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/react-core/src/components/Progress/ProgressContainer.tsx b/packages/react-core/src/components/Progress/ProgressContainer.tsx index 91f27e7ba7c..9e5178f9131 100644 --- a/packages/react-core/src/components/Progress/ProgressContainer.tsx +++ b/packages/react-core/src/components/Progress/ProgressContainer.tsx @@ -1,4 +1,4 @@ -import { Fragment, useState } from 'react'; +import { Fragment, useState, useRef, useEffect } from 'react'; import progressStyle from '@patternfly/react-styles/css/components/Progress/progress'; import { css } from '@patternfly/react-styles'; import { Tooltip, TooltipPosition } from '../Tooltip'; @@ -80,13 +80,21 @@ export const ProgressContainer: React.FunctionComponent }: ProgressContainerProps) => { const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant]; const [tooltip, setTooltip] = useState(''); - const onMouseEnter = (event: any) => { + const titleRef = useRef(null); + const onFocus = (event: any) => { if (event.target.offsetWidth < event.target.scrollWidth) { setTooltip(title || event.target.innerHTML); } else { setTooltip(''); } }; + + useEffect(() => { + if (tooltip !== '') { + titleRef.current.focus(); + } + }, [tooltip]); + const Title = (
)} id={`${parentId}-description`} aria-hidden="true" - onMouseEnter={isTitleTruncated && typeof title === 'string' ? onMouseEnter : null} + onMouseEnter={isTitleTruncated && typeof title === 'string' ? onFocus : null} + onFocus={isTitleTruncated && typeof title === 'string' ? onFocus : null} + {...(isTitleTruncated && typeof title === 'string' && { tabIndex: 0 })} + ref={titleRef} > {title}
@@ -103,14 +114,12 @@ export const ProgressContainer: React.FunctionComponent return ( - {title && - (tooltip ? ( - - {Title} - - ) : ( - Title - ))} + {title && ( + <> + {tooltip && } + {Title} + + )} {(measureLocation !== ProgressMeasureLocation.none || StatusIcon) && (