Skip to content

Commit

Permalink
fix flicker on safari
Browse files Browse the repository at this point in the history
  • Loading branch information
radumojic committed Dec 14, 2023
1 parent 217884d commit 813cf91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions src/components/TransactionsTable/components/TransactionMethod.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from 'react';
import { useRef, useState, useLayoutEffect } from 'react';
import classNames from 'classnames';
import { useSearchParams } from 'react-router-dom';

Expand All @@ -13,8 +13,15 @@ export interface TransactionMethodType {
export const TransactionMethod = ({ transaction }: TransactionMethodType) => {
const badgeTextRef = useRef(null);
const [searchParams, setSearchParams] = useSearchParams();
const [isTextTruncated, setIsTextTruncated] = useState(false);
const { function: filteredFunction } = Object.fromEntries(searchParams);

useLayoutEffect(() => {
if (badgeTextRef?.current) {
setIsTextTruncated(isEllipsisActive(badgeTextRef?.current));
}
}, []);

const transactionMethodText = getTransactionMethod(transaction);
if (!transactionMethodText) {
return null;
Expand All @@ -24,8 +31,7 @@ export const TransactionMethod = ({ transaction }: TransactionMethodType) => {
transaction.action?.description &&
transaction.action.description !== 'Transfer'
);
const showTooltip =
isEllipsisActive(badgeTextRef?.current) || showDescription;
const showTooltip = showDescription || isTextTruncated;

const updateMethod = (method: string) => {
const { page, size, ...rest } = Object.fromEntries(searchParams);
Expand Down Expand Up @@ -81,11 +87,11 @@ export const TransactionMethod = ({ transaction }: TransactionMethodType) => {
</div>
);

const TransactionMethodTooltip = () => {
if (showTooltip) {
return (
return showTooltip ? (
<Overlay
title={
<>
{isEllipsisActive(badgeTextRef?.current) && (
{isTextTruncated && (
<p className={classNames({ 'mb-0': !showDescription })}>
{transactionMethodText}
</p>
Expand All @@ -94,14 +100,9 @@ export const TransactionMethod = ({ transaction }: TransactionMethodType) => {
<p className='mb-0'>{transaction.action?.description}</p>
)}
</>
);
}

return null;
};

return showTooltip ? (
<Overlay title={<TransactionMethodTooltip />} className='method-tooltip'>
}
className='method-tooltip'
>
<TransactionMethodBadge />
</Overlay>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/isEllipsisActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const isEllipsisActive = (e?: HTMLDivElement | null) => {
}
}

return false;
return true;
};

0 comments on commit 813cf91

Please sign in to comment.