fix(PopOver): support translated content and ensure proper outside click behaviour - #232
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the PopOver component to support optional visual translation and ensures it closes correctly when clicking outside, even if shifted. It also tightens Storybook configuration and corrects a story import path.
- Introduces
popOverTranslationprop and updates types. - Adjusts PopOver rendering logic with transform offsets and adds outside-click handling.
- Updates tests, story MDX import, and Storybook manager fallback.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/elements/PopOver/types.ts | Added popOverTranslation prop and updated StyledPopOverContainerProps |
| ui/elements/PopOver/PopOver.tsx | Applies dynamic translation, adds outside-click effect |
| ui/elements/PopOver/PopOver.test.tsx | Adds a basic rendering test for popOverTranslation |
| ui/elements/PopOver/PopOver.styles.ts | Removed extraneous whitespace |
| stories/elements/Accordion/index.mdx | Corrected MDX import path |
| .storybook/manager.js | Provided fallback when themeKey is missing or invalid |
Comments suppressed due to low confidence (1)
ui/elements/PopOver/PopOver.test.tsx:68
- The new test verifies rendering but does not assert that the translation is actually applied. Consider checking the PopOver container’s
style.transformor position to ensure the translation offsets are applied as expected.
expect(screen.getByText('PopOver Content')).toBeInTheDocument();
| setFirstOffsetSet(true); | ||
|
|
||
| // Simulate a transform by modifying top and left | ||
| setAdjustedOffset({ |
There was a problem hiding this comment.
The effect that sets the initial offset never marks firstOffsetSet as true, so it will re-run continuously. After updating adjustedOffset, you should call setFirstOffsetSet(true) to prevent repeated recalculation.
| {...motionProps} | ||
| variants={getMotionVariants(direction)} | ||
| style={{ | ||
| transform: `translate(${popOverTranslation?.x || 0}px, ${popOverTranslation?.y || 0}px)` |
There was a problem hiding this comment.
You’re both adjusting top/left by the translation and applying a CSS transform of the same values, causing double translation. Choose one approach: apply the translation via CSS transform only or adjust the offset calculation, but not both.
| @@ -1,5 +1,5 @@ | |||
| import { Meta, DocsPage } from '@storybook/blocks'; | |||
| import * as AccordionStories from './index.stories'; | |||
| import * as AccordionStories from "../PopOver/index.stories"; | |||
There was a problem hiding this comment.
The MDX for the Accordion story imports from the PopOver folder. It should import Accordion stories (e.g., from './index.stories' or the correct Accordion path) to avoid documentation errors.
| import * as AccordionStories from "../PopOver/index.stories"; | |
| import * as AccordionStories from "./index.stories"; |
| * @default true | ||
| */ | ||
| shouldFocusOnFirstElement?: boolean; | ||
|
|
There was a problem hiding this comment.
[nitpick] The new popOverTranslation prop lacks a JSDoc comment. Adding a brief description and default behavior will improve clarity for consumers and maintainers.
| /** | |
| * Translation offsets for the PopOver position. | |
| * Allows fine-tuning of the PopOver's placement by specifying x and y offsets. | |
| * @default { x: 0, y: 0 } | |
| */ |
🔧 Changes Made
popOverTranslationprop to<PopOver />for supporting content translation via transform.transform: translate(...)style dynamically based on the passed prop.types.tsto support new translation prop.PopOver.test.tsxto include visual translation behavior..storybook/manager.jsto prevent theme crash (tokensundefined).🧪 How to Test
popOverTranslation={{ x: 300, y: 200 }}.x/ytranslation values to verify consistent behavior.✅ Fixes
Closes #100 – Popover should close on outside click even when visually translated
Test Video
Screen.Recording.2025-05-21.at.7.38.24.AM.mov