Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/react-core/src/helpers/Popper/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,16 @@ export const Popper: React.FunctionComponent<PopperProps> = ({

return (
<>
{!triggerRef && trigger && React.isValidElement(trigger) && (

{!reference && trigger && React.isValidElement(trigger) && (

<div style={{ display: 'contents' }} ref={(node) => setTriggerElement(node?.firstElementChild as HTMLElement)}>
{trigger}
</div>
)}
{triggerRef && trigger && React.isValidElement(trigger) && trigger}

{reference && trigger && React.isValidElement(trigger) && trigger}

{ready && isVisible && getPopper()}
</>
);
Expand Down
1 change: 1 addition & 0 deletions packages/react-table/src/components/Table/HeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const HeaderCell: React.FunctionComponent<HeaderCellProps> = ({
scope={scope}
tooltip={tooltip}
onMouseEnter={onMouseEnter}
focusable={false}
textCenter={textCenter}
component={component}
className={className}
Expand Down
7 changes: 5 additions & 2 deletions packages/react-table/src/components/Table/SortColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
...props
}: SortColumnProps) => {
let SortedByIcon;
const [focused, setFocused] = React.useState(false);
if (isSortedBy) {
SortedByIcon = sortDirection === SortByDirection.asc ? LongArrowAltUpIcon : LongArrowAltDownIcon;
} else {
Expand All @@ -39,10 +40,12 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
{...props}
type={type}
className={css(className, styles.tableButton)}
onClick={event => onSort && onSort(event)}
onClick={(event) => onSort && onSort(event)}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
>
<div className={css(className, styles.tableButtonContent)}>
<TableText>{children}</TableText>
<TableText focused={focused}>{children}</TableText>
<span className={css(styles.tableSortIndicator)}>
<SortedByIcon />
</span>
Expand Down
33 changes: 30 additions & 3 deletions packages/react-table/src/components/Table/TableText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface TableTextProps extends React.HTMLProps<HTMLDivElement> {
tooltipProps?: Omit<TooltipProps, 'content'>;
/** callback used to create the tooltip if text is truncated */
onMouseEnter?: (event: any) => void;

focused?: boolean;
}

export const TableText: React.FunctionComponent<TableTextProps> = ({
Expand All @@ -41,10 +43,13 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
tooltip: tooltipProp = '',
tooltipProps = {},
onMouseEnter: onMouseEnterProp = () => {},
focused = false,
...props
}: TableTextProps) => {
const Component: TableTextVariant | 'span' | 'div' = variant;
const textRef = React.createRef<any>();

const textRef = React.createRef<HTMLElement>();


const [tooltip, setTooltip] = React.useState('');
const onMouseEnter = (event: any) => {
Expand All @@ -56,19 +61,41 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
onMouseEnterProp(event);
};

const onFocus = (element: HTMLElement) => {
if (element.offsetWidth < element.scrollWidth) {
setTooltip(tooltipProp || element.innerText);
} else {
setTooltip('');
}
};

const text = (
<Component
ref={textRef}

ref={textRef as React.Ref<any>}


onMouseEnter={onMouseEnter}

className={css(className, wrapModifier && styles.modifiers[wrapModifier], styles.tableText)}
{...props}
>
{children}
</Component>
);

React.useEffect(() => {
if (focused) {
onFocus(textRef.current);
} else {
setTooltip('');
}
}, [focused]);

return tooltip !== '' ? (
<Tooltip triggerRef={textRef} content={tooltip} isVisible {...tooltipProps}>

<Tooltip reference={textRef} content={tooltip} isVisible {...tooltipProps}>

{text}
</Tooltip>
) : (
Expand Down
25 changes: 23 additions & 2 deletions packages/react-table/src/components/TableComposable/Td.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ const TdBase: React.FunctionComponent<TdProps> = ({
...props
}: TdProps) => {
const [showTooltip, setShowTooltip] = React.useState(false);

const [truncated, setTruncated] = React.useState(false);
const cellRef = innerRef ? innerRef : React.createRef();


const onMouseEnter = (event: any) => {
if (event.target.offsetWidth < event.target.scrollWidth) {
!showTooltip && setShowTooltip(true);
} else {
showTooltip && setShowTooltip(false);
}

onMouseEnterProp(event);
};

Expand Down Expand Up @@ -246,9 +250,19 @@ const TdBase: React.FunctionComponent<TdProps> = ({
(className && className.includes('pf-c-table__tree-view-title-cell')) ||
(mergedClassName && mergedClassName.includes('pf-c-table__tree-view-title-cell'));

React.useEffect(() => {
setTruncated(
(cellRef as React.RefObject<HTMLElement>).current.offsetWidth <
(cellRef as React.RefObject<HTMLElement>).current.scrollWidth
);
}, [cellRef]);

const cell = (
<MergedComponent
tabIndex={(select || !truncated) && modifier !== 'truncate' ? -1 : 0}
{...(!treeTableTitleCell && { 'data-label': dataLabel })}
onFocus={tooltip !== null ? onMouseEnter : onMouseEnterProp}
onBlur={() => setShowTooltip(false)}
onMouseEnter={tooltip !== null ? onMouseEnter : onMouseEnterProp}
className={css(
className,
Expand Down Expand Up @@ -278,9 +292,16 @@ const TdBase: React.FunctionComponent<TdProps> = ({

const canMakeDefaultTooltip = tooltip === '' ? typeof children === 'string' : true;
return tooltip !== null && canMakeDefaultTooltip && showTooltip ? (
<Tooltip triggerRef={cellRef as React.RefObject<any>} content={tooltip || (tooltip === '' && children)} isVisible>

<>

{cell}
</Tooltip>
<Tooltip
reference={cellRef as React.RefObject<any>}
content={tooltip || (tooltip === '' && children)}
isVisible
/>
</>
) : (
cell
);
Expand Down
27 changes: 25 additions & 2 deletions packages/react-table/src/components/TableComposable/Th.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface ThProps
stickyLeftOffset?: string;
/** Indicates the <th> is part of a subheader of a nested header */
isSubheader?: boolean;

focusable?: boolean;
}

const ThBase: React.FunctionComponent<ThProps> = ({
Expand All @@ -76,9 +78,13 @@ const ThBase: React.FunctionComponent<ThProps> = ({
stickyMinWidth = '120px',
stickyLeftOffset,
isSubheader = false,
focusable = true,
...props
}: ThProps) => {
const [showTooltip, setShowTooltip] = React.useState(false);

const [truncated, setTruncated] = React.useState(false);

const cellRef = innerRef ? innerRef : React.createRef();
const onMouseEnter = (event: any) => {
if (event.target.offsetWidth < event.target.scrollWidth) {
Expand Down Expand Up @@ -160,8 +166,18 @@ const ThBase: React.FunctionComponent<ThProps> = ({
...mergedProps
} = merged;

React.useEffect(() => {
setTruncated(
(cellRef as React.RefObject<HTMLElement>).current.offsetWidth <
(cellRef as React.RefObject<HTMLElement>).current.scrollWidth
);
}, [cellRef]);

const cell = (
<MergedComponent
tabIndex={sort || select || !focusable || !truncated ? -1 : 0}
onFocus={tooltip !== null ? onMouseEnter : onMouseEnterProp}
onBlur={() => setShowTooltip(false)}
data-label={dataLabel}
onMouseEnter={tooltip !== null ? onMouseEnter : onMouseEnterProp}
scope={component === 'th' && children ? scope : null}
Expand Down Expand Up @@ -191,9 +207,16 @@ const ThBase: React.FunctionComponent<ThProps> = ({

const canMakeDefaultTooltip = tooltip === '' ? typeof transformedChildren === 'string' : true;
return tooltip !== null && canMakeDefaultTooltip && showTooltip ? (
<Tooltip triggerRef={cellRef as React.RefObject<any>} content={tooltip || (tooltip === '' && children)} isVisible>

<>

{cell}
</Tooltip>
<Tooltip
reference={cellRef as React.RefObject<any>}
content={tooltip || (tooltip === '' && children)}
isVisible
/>
</>
) : (
cell
);
Expand Down