Closed cheton closed 1 month ago
Open the branch in Web Editor • VS Code • Insiders
Open Preview
Latest commit: 9f77a504685929c5ed0798b60341ff2ae14f55c0
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
β±οΈ Estimated effort to review: 3 π΅π΅π΅βͺβͺ |
π§ͺ No relevant tests |
π No security concerns identified |
β‘ Key issues to review Complex Calculation The offset calculation logic in `TooltipContent.js` has been significantly refactored to include complex conditions and calculations based on the tooltip's placement and cursor position. This could potentially introduce bugs or performance issues due to the complexity and dependency on multiple conditions and external measurements. It is recommended to add unit tests specifically targeting these calculations to ensure their correctness under various scenarios. Default Prop Change The default props for `offset` and `placement` have been changed in `OverflowTooltip.js`. This alteration affects all instances of `OverflowTooltip` across the project. It's crucial to ensure that these changes do not adversely affect existing functionalities where `OverflowTooltip` is used. |
/improve
Latest suggestions up to 9f77a50
Category | Suggestion | Score |
Enhancement |
Add
___
**To improve the accessibility and user experience, consider adding | 9 |
Possible issue |
Add conditional rendering to the
___
**Consider adding a conditional rendering check for the | 8 |
Maintainability |
Refactor offset calculation to a separate function for clarity___ **Refactor the offset calculation in thepopperModifiers to a separate function to improve code readability and maintainability.** [packages/react/src/tooltip/TooltipContent.js [71-127]](https://github.com/trendmicro-frontend/tonic-ui/pull/897/files#diff-1f36317cf4d70085ec792a74b9088f7722f10ffc97999b65c3524729941a9722R71-R127) ```diff +const calculateOffset = ({ placement, reference, popper }) => { + let computedSkidding = ensureFiniteNumber(skidding); + let computedDistance = ensureFiniteNumber(distance); + ... + return [computedSkidding, computedDistance]; +}; + const popperModifiers = useMemo(() => [ { name: 'offset', options: { - offset: ({ placement, reference, popper }) => { - let computedSkidding = ensureFiniteNumber(skidding); - let computedDistance = ensureFiniteNumber(distance); - ... - return [computedSkidding, computedDistance]; - }, + offset: calculateOffset, }, }, ], [skidding, distance, tooltipTriggerElement, followCursor, nextToCursor, mousePageX, mousePageY]); ``` Suggestion importance[1-10]: 7Why: This refactoring improves code readability and maintainability, making it easier to understand and modify the offset calculation logic in the future. | 7 |
Possible bug |
Add a default value for
___
**It's recommended to handle potential undefined or null values for | 6 |
Category | Suggestion | Score |
Maintainability |
Extract complex logic into a separate function for clarity___ **ThepopperModifiers logic is complex and could benefit from being extracted into a separate function or utility. This would make TooltipContent cleaner and focus more on rendering logic rather than computational logic.** [packages/react/src/tooltip/TooltipContent.js [71-127]](https://github.com/trendmicro-frontend/tonic-ui/pull/897/files#diff-1f36317cf4d70085ec792a74b9088f7722f10ffc97999b65c3524729941a9722R71-R127) ```diff +const calculateOffset = ({ placement, reference, popper }) => { + ... + return [computedSkidding, computedDistance]; +}; + const popperModifiers = useMemo(() => [ { name: 'offset', options: { - offset: ({ placement, reference, popper }) => { - ... - }, + offset: calculateOffset, }, }, ], [skidding, distance, tooltipTriggerElement, followCursor, nextToCursor, mousePageX, mousePageY]); ``` Suggestion importance[1-10]: 8Why: Extracting the complex `popperModifiers` logic into a separate function enhances code readability and maintainability by separating computational logic from rendering logic. | 8 |
Use descriptive function names for better code readability___ **It's recommended to use a more descriptive variable name thanchangeBy for the function returned from useSelection . A name like updatePlacement would make the code more readable and clearly indicate its purpose.** [packages/react-docs/pages/components/tooltip/positioning-follow-cursor.js [31]](https://github.com/trendmicro-frontend/tonic-ui/pull/897/files#diff-5435045d19a1d554b8291cec6959b4c2779fc2755d93ce5e18cfc8b259c807fdR31-R31) ```diff -const [placement, changePlacementBy] = useSelection('bottom-end'); +const [placement, updatePlacement] = useSelection('bottom-end'); ``` Suggestion importance[1-10]: 7Why: The suggestion to rename `changePlacementBy` to `updatePlacement` improves code readability and maintainability by making the function's purpose clearer. | 7 | |
Enhancement |
Add
___
**To prevent potential layout issues in different browsers, consider setting explicit | 6 |
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 74.84%. Comparing base (
0736f0e
) to head (9f77a50
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Tooltip
https://trendmicro-frontend.github.io/tonic-ui-demo/react/pr-897/components/tooltip
OverflowTooltip
https://trendmicro-frontend.github.io/tonic-ui-demo/react/pr-897/components/overflow-tooltip
PR Type
Enhancement, Documentation
Description
placement
prop instead ofnextToCursor
.TooltipContent
.placement
andoffset
props forOverflowTooltip
andTooltip
components.Changes walkthrough π
7 files
faq-relative-to-reference-element.js
Update tooltip placement in OverflowTooltip example.
packages/react-docs/pages/components/overflow-tooltip/faq-relative-to-reference-element.js
nextToCursor
prop toplacement
prop with valuebottom
.positioning-follow-cursor.js
Add placement selection and update tooltip positioning.
packages/react-docs/pages/components/tooltip/positioning-follow-cursor.js
positioning-next-cursor.js
Add placement selection and update tooltip positioning.
packages/react-docs/pages/components/tooltip/positioning-next-cursor.js
positioning-offset.js
Add placement selection and update tooltip positioning.
packages/react-docs/pages/components/tooltip/positioning-offset.js
OverflowTooltip.js
Add offset and placement props to OverflowTooltip.
packages/react/src/tooltip/OverflowTooltip.js - Added `offset` and `placement` props with default values.
Tooltip.js
Simplify tooltip placement logic.
packages/react/src/tooltip/Tooltip.js - Simplified placement logic.
TooltipContent.js
Refactor offset calculation logic in TooltipContent.
packages/react/src/tooltip/TooltipContent.js - Refactored offset calculation logic based on placement.
2 files
index.page.mdx
Document default placement and offset for OverflowTooltip.
packages/react-docs/pages/components/overflow-tooltip/index.page.mdx
placement
andoffset
props.index.page.mdx
Document default placement and offset for Tooltip.
packages/react-docs/pages/components/tooltip/index.page.mdx
placement
andoffset
props.