Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 7 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ const withThemeProvider = (Story, context) => {
<QueryClientProvider client={new QueryClient()}>
<CoreUiThemeProvider theme={theme}>
{/* Wrapper to make the stories take the full screen but not in docs */}
<div
style={
viewMode === 'story'
? { height: 100 + 'vh', overflow: 'scroll' }
: null
}
>
<div style={viewMode === 'story' ? { height: 100 + 'vh' } : null}>
<ToastProvider>
<Wrapper style={{ backgroundColor: background }}>
<Story {...context} />
Expand Down
55 changes: 30 additions & 25 deletions src/lib/components/tooltip/Tooltip.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computePosition, flip, offset, shift } from '@floating-ui/dom';
import { CSSProperties, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components';
import { spacing } from '../../spacing';
import { fontSize, zIndex } from '../../style/theme';
Expand Down Expand Up @@ -98,38 +99,42 @@ function Tooltip({
if (tooltipRef.current) {
Object.assign(tooltipRef.current.style, {
opacity: '1',
// we set opacity to 1 to make sure the tooltip is not displayed before the position is computed
left: `${x}px`,
top: `${y}px`,
});
}
});
}
}, [tooltipRef.current, childrenRef.current, isTooltipVisible]);
}, [isTooltipVisible, placement]);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect dependencies array is missing childrenRef and tooltipRef. The effect uses childrenRef.current and tooltipRef.current internally. While refs themselves don't change, this could lead to stale closures. Consider adding these refs to the dependency array or using a callback ref pattern to ensure proper updates when the refs are set.

Suggested change
}, [isTooltipVisible, placement]);
}, [isTooltipVisible, placement, childrenRef, tooltipRef]);

Copilot uses AI. Check for mistakes.
return (
<TooltipContainer
className="sc-tooltip"
onPointerEnter={() => {
setIsTooltipVisible(true);
}}
onPointerLeave={() => {
setIsTooltipVisible(false);
}}
>
{isTooltipVisible && overlay ? (
<TooltipOverLayContainer
ref={tooltipRef}
className="sc-tooltip-overlay"
placement={placement}
style={overlayStyle}
>
<TooltipText className="sc-tooltip-overlay-text">
{overlay}
</TooltipText>
</TooltipOverLayContainer>
) : null}
<div ref={childrenRef}>{children}</div>
</TooltipContainer>
<>
<TooltipContainer
className="sc-tooltip"
onPointerEnter={() => {
setIsTooltipVisible(true);
}}
onPointerLeave={() => {
setIsTooltipVisible(false);
}}
Comment on lines +98 to +103
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The event handlers create new function instances on every render. Consider using useCallback to memoize these handlers for better performance, especially if the tooltip is used frequently in lists or tables.

Copilot uses AI. Check for mistakes.
>
<div ref={childrenRef}>{children}</div>
</TooltipContainer>
{isTooltipVisible &&
overlay &&
createPortal(
<TooltipOverLayContainer
ref={tooltipRef}
className="sc-tooltip-overlay"
placement={placement}
style={overlayStyle}
>
<TooltipText className="sc-tooltip-overlay-text">
{overlay}
</TooltipText>
</TooltipOverLayContainer>,
document.body,
)}
</>
);
}

Expand Down
2 changes: 1 addition & 1 deletion stories/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const StyledWrapper = styled.div`
background-color: ${theme[style?.backgroundColor || 'backgroundLevel3']};
color: ${theme.textPrimary};
box-sizing: border-box;
overflow: scroll;
overflow: auto;
`;
}}
`;
Expand Down
2 changes: 1 addition & 1 deletion stories/tablev2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export const TableWithSyncButton = {
};

return (
<Box>
<Box width="500px" height="250px">
<Title>Table with Sync Button</Title>
<Box
display="flex"
Expand Down
Loading