Skip to content

feat: add arrow size property #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WoodyWoodsta
Copy link

@WoodyWoodsta WoodyWoodsta commented Jun 6, 2025

Fixes #1250

  • Adds arrowSize property, which controls positioning as well as a css variable used to style the height and width of the arrow element
  • Sets the arrow element to a z-index of -1 so that it renders behind the tooltip content, otherwise larger arrow sizes cover the content.

Summary by CodeRabbit

  • New Features

    • Added support for customizing the tooltip arrow size via a new optional property, allowing users to specify the arrow size for tooltips.
  • Style

    • Tooltip arrow size is now configurable through a CSS variable.
    • Adjusted tooltip arrow stacking order to appear behind other elements.

Copy link

coderabbitai bot commented Jun 6, 2025

Walkthrough

The changes introduce an arrowSize prop to the Tooltip and TooltipController components, allowing dynamic control of the tooltip arrow's size. This prop is propagated through type definitions, positioning logic, and CSS, ensuring that both the visual size and computed position of the arrow adjust according to the specified value.

Changes

Files/Groups Change Summary
src/components/Tooltip/Tooltip.tsx, TooltipTypes.d.ts Added optional arrowSize prop to Tooltip component and its type definition.
src/components/TooltipController/TooltipController.tsx, TooltipControllerTypes.d.ts Added optional arrowSize prop to TooltipController and its type definition.
src/utils/compute-tooltip-position.ts, compute-tooltip-position-types.d.ts Added arrowSize parameter to computeTooltipPosition and its types; used for arrow offset calculation.
src/components/Tooltip/core-styles.module.css Added z-index: -1 to .arrow class.
src/components/Tooltip/styles.module.css Replaced fixed arrow dimensions with --rt-arrow-size CSS variable for dynamic sizing.

Sequence Diagram(s)

sequenceDiagram
    participant Consumer
    participant TooltipController
    participant Tooltip
    participant computeTooltipPosition

    Consumer->>TooltipController: Pass arrowSize prop
    TooltipController->>Tooltip: Forward arrowSize prop
    Tooltip->>computeTooltipPosition: Call with arrowSize
    computeTooltipPosition-->>Tooltip: Return position using arrowSize
    Tooltip->>Tooltip: Set --rt-arrow-size CSS variable
    Tooltip->>DOM: Render arrow with correct size and position
Loading

Assessment against linked issues

Objective Addressed Explanation
Ability to update arrow height/width and have position computed correctly (#1250)
Make arrow size configurable via prop and reflected in positioning and styling (#1250)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Added z-index: -1 to .arrow class (src/components/Tooltip/core-styles.module.css) This change affects stacking order and is not directly related to arrow sizing or positioning.

Poem

A tooltip’s arrow, once fixed in its place,
Now grows or shrinks with elegant grace.
With arrowSize set, it’s easy to see—
The pointer aligns, as neat as can be!
🐇✨ Hooray for flexibility,
In every tooltip’s geometry!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/components/Tooltip/TooltipTypes.d.ts (1)

161-161: Consider adding documentation and type constraints.

The arrowSize property addition looks good. Consider enhancing it with:

  1. JSDoc documentation for clarity:
  arrowColor?: CSSProperties['backgroundColor']
+  /**
+   * @description Size of the tooltip arrow in pixels.
+   * @default 8
+   */
  arrowSize?: number
  1. Type constraint to ensure positive values:
arrowSize?: number & { __brand: 'PositiveNumber' }

Or consider runtime validation in the component to ensure sensible values (e.g., > 0).

src/components/TooltipController/TooltipControllerTypes.d.ts (1)

94-94: Consider adding documentation for consistency.

The arrowSize property addition maintains good consistency with the ITooltip interface. Consider adding JSDoc documentation for user clarity:

  arrowColor?: CSSProperties['backgroundColor']
+  /**
+   * @description Size of the tooltip arrow in pixels.
+   * @default 8
+   */
  arrowSize?: number

This would align with the documentation style used elsewhere in the interface and provide clear guidance to developers.

src/components/Tooltip/Tooltip.tsx (1)

906-906: Consider input validation for arrowSize.

The CSS variable is correctly set with pixel units. However, consider adding validation to ensure arrowSize is a positive number to prevent unexpected styling behavior.

Example validation:

  style={{
    ...computedPosition.tooltipArrowStyles,
    background: arrowColor
      ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
      : undefined,
-   '--rt-arrow-size': `${arrowSize}px`,
+   '--rt-arrow-size': `${Math.max(0, arrowSize || 8)}px`,
  }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c448c3 and 5d0eb7d.

⛔ Files ignored due to path filters (2)
  • src/test/__snapshots__/tooltip-attributes.spec.js.snap is excluded by !**/*.snap
  • src/test/__snapshots__/tooltip-props.spec.js.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • src/components/Tooltip/Tooltip.tsx (5 hunks)
  • src/components/Tooltip/TooltipTypes.d.ts (1 hunks)
  • src/components/Tooltip/core-styles.module.css (1 hunks)
  • src/components/Tooltip/styles.module.css (1 hunks)
  • src/components/TooltipController/TooltipController.tsx (2 hunks)
  • src/components/TooltipController/TooltipControllerTypes.d.ts (1 hunks)
  • src/utils/compute-tooltip-position-types.d.ts (1 hunks)
  • src/utils/compute-tooltip-position.ts (2 hunks)
🔇 Additional comments (7)
src/components/Tooltip/core-styles.module.css (1)

17-17: LGTM! Prevents arrow overlap with larger sizes.

The z-index: -1 effectively addresses the overlap issue mentioned in the PR objectives, ensuring larger arrow sizes render behind the tooltip content rather than covering it.

src/utils/compute-tooltip-position-types.d.ts (1)

13-13: Clean type definition addition.

The optional arrowSize property with number type is well-defined and consistent with the implementation that provides a default value.

src/components/Tooltip/Tooltip.tsx (3)

71-71: Good default value and prop definition.

The arrowSize = 8 default is reasonable and consistent with the positioning logic that previously used a hardcoded value of 4 (which equals 8/2).


349-349: Correct integration with positioning logic.

The arrowSize prop is properly passed to both computeTooltipPosition calls, ensuring consistent arrow positioning for both virtual element and active anchor scenarios.

Also applies to: 442-442


462-462: Proper dependency management.

Adding arrowSize to the dependency array ensures the tooltip position is recalculated when the arrow size changes, which is necessary for accurate positioning.

src/components/TooltipController/TooltipController.tsx (1)

61-61: Clean prop forwarding implementation.

The arrowSize prop is correctly destructured and forwarded to the underlying Tooltip component, following the established pattern for other props in the controller.

Also applies to: 372-372

src/utils/compute-tooltip-position.ts (1)

19-19: Correct calculation logic and backward compatibility.

The arrowSize = 8 default maintains backward compatibility since the previous hardcoded value was 4 (8/2 = 4). The calculation arrowSize / 2 + borderWidth correctly positions the arrow by using half the arrow size plus any border width.

The mathematical logic makes sense: the arrow offset should be half the arrow size to center it properly relative to the tooltip edge.

Also applies to: 82-82

Comment on lines +9 to +10
width: var(--rt-arrow-size);
height: var(--rt-arrow-size);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add fallback value for CSS variable.

Consider adding a fallback value to ensure the arrow has a size even if the CSS variable is not set:

-.arrow {
-  width: var(--rt-arrow-size);
-  height: var(--rt-arrow-size);
-}
+.arrow {
+  width: var(--rt-arrow-size, 8px);
+  height: var(--rt-arrow-size, 8px);
+}

This provides backwards compatibility and prevents potential layout issues if the variable is undefined.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
width: var(--rt-arrow-size);
height: var(--rt-arrow-size);
/* src/components/Tooltip/styles.module.css */
.arrow {
width: var(--rt-arrow-size, 8px);
height: var(--rt-arrow-size, 8px);
}
🤖 Prompt for AI Agents
In src/components/Tooltip/styles.module.css at lines 9 to 10, the CSS properties
width and height use the variable --rt-arrow-size without fallback values. To
fix this, add fallback values to both properties using the CSS var() function
syntax, for example var(--rt-arrow-size, 10px), so the arrow size defaults to a
specific value if the variable is not defined, preventing layout issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Unable to change arrow size
1 participant