Skip to content
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

feat: support for disabled tooltip callback #1211

Merged

Conversation

nareshpingale
Copy link
Contributor

@nareshpingale nareshpingale commented Jul 21, 2024

Addresse #1210

Usage:

   <button
      data-tooltip-id="anchor-select"
      data-tooltip-content="this content is different"
      data-tooltip-dynamic="true"
      style={{
        maxWidth: '200px',
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap',
      }}
    >
      Anchor select with dynamic tooltip and a very long label to test overflow
    </button>
    <button data-tooltip-id="anchor-select" data-tooltip-dynamic="true">
      Anchor select with dynamic tooltip
    </button>
    <button data-tooltip-id="anchor-select">Anchor select without dynamic tooltip</button>
  </p>
  <Tooltip
    id="anchor-select"
    disableTooltip={(anchor) => {
      const { scrollWidth, offsetWidth } = anchor as HTMLElement
      if (anchor?.getAttribute('data-tooltip-dynamic') && scrollWidth <= offsetWidth) {
        return true
      }

      return false
    }}
  >
    Tooltip content
  </Tooltip>
Screen.Recording.2024-07-21.at.10.15.51.PM.mov

Summary by CodeRabbit

  • New Features

    • Introduced a new optional prop disableTooltip for the Tooltip component, allowing developers to conditionally disable tooltips for specific anchors.
    • Enhanced the TooltipController component to support the new disableTooltip functionality, improving control over tooltip display behavior.
  • Documentation

    • Updated documentation to include the new disableTooltip function, providing guidance on controlling tooltip visibility based on anchor states.
  • Tests

    • Added test cases to validate the behavior of the disableTooltip prop, ensuring tooltips render correctly based on the prop's return value.

Copy link

coderabbitai bot commented Jul 21, 2024

Walkthrough

The recent changes introduce a new optional prop, disableTooltip, that allows developers to conditionally disable tooltips for specific anchors. This enhancement improves flexibility and control over tooltip visibility across various components, including the Tooltip, TooltipController, and their respective TypeScript interfaces, ensuring seamless integration within the existing codebase.

Changes

Files Change Summary
src/components/Tooltip/Tooltip.tsx, Added disableTooltip prop to the Tooltip component for conditional tooltip disabling based on anchor logic.
src/components/TooltipTypes.d.ts Introduced disableTooltip method in ITooltip interface for controlling tooltip display behavior per anchor.
src/components/TooltipController/TooltipController.tsx, Added disableTooltip prop to TooltipController, impacting tooltip rendering according to this new functionality.
src/components/TooltipControllerTypes.d.ts Added disableTooltip method to ITooltipController interface for managing tooltip visibility based on anchor state.
docs/docs/options.mdx Documented the new disableTooltip function, detailing its use for controlling tooltip visibility per anchor.
src/test/tooltip-props.spec.js Added tests for disableTooltip prop behavior in TooltipProps, validating rendering logic based on its return value.

Poem

🐇 In the garden where tooltips play,
A new prop hops in to brighten the day!
"Disable me," it cheerfully sings,
Allowing more joy to the tooltip flings.
With anchors that dance and twirl with grace,
Conditional whispers now take their place!
🌸✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Outside diff range, codebase verification and nitpick comments (1)
src/components/Tooltip/Tooltip.tsx (1)

463-465: Ensure consistent code style and improve readability.

The conditional check for disableTooltip can be made more readable by using early return.

-      if(disableTooltip?.(anchor)){
-        return;
-      }
+      if (disableTooltip?.(anchor)) {
+        return
+      }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 143221a and 962a660.

Files selected for processing (4)
  • src/components/Tooltip/Tooltip.tsx (2 hunks)
  • src/components/Tooltip/TooltipTypes.d.ts (1 hunks)
  • src/components/TooltipController/TooltipController.tsx (2 hunks)
  • src/components/TooltipController/TooltipControllerTypes.d.ts (1 hunks)
Additional comments not posted (4)
src/components/TooltipController/TooltipControllerTypes.d.ts (1)

97-97: New method disableTooltip added to ITooltipController.

The method is correctly typed and aligns with the described functionality.

src/components/Tooltip/TooltipTypes.d.ts (1)

155-155: New method disableTooltip added to ITooltip.

The method is correctly typed and aligns with the described functionality.

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

64-64: New parameter disableTooltip added to TooltipController props.

The parameter is correctly added to the destructuring assignment in the component definition.


374-374: New parameter disableTooltip added to Tooltip props.

The parameter is correctly added to the props passed to the Tooltip component.

src/components/Tooltip/Tooltip.tsx Show resolved Hide resolved
@nareshpingale
Copy link
Contributor Author

@gabrieljablonski do let me know if we need to update /examples for this. Also if everything looks fine at first glance will start adding changes to /docs.

Copy link
Member

@gabrieljablonski gabrieljablonski left a comment

Choose a reason for hiding this comment

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

Looks good for a first pass. If you don't mind, please add it to the "options" table on the docs.

Also, if you could try adding a test for the new prop under this tests file, we'd appreciate it. No need to waste too much time on it though if you can't figure it out.

When those are done we'll do a last check again and see if we catch anything. The feature is simple enough, but just to make sure.

src/components/Tooltip/Tooltip.tsx Outdated Show resolved Hide resolved
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 962a660 and 263138a.

Files ignored due to path filters (1)
  • src/test/__snapshots__/tooltip-props.spec.js.snap is excluded by !**/*.snap
Files selected for processing (3)
  • docs/docs/options.mdx (1 hunks)
  • src/components/Tooltip/Tooltip.tsx (2 hunks)
  • src/test/tooltip-props.spec.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/Tooltip/Tooltip.tsx
Additional comments not posted (3)
src/test/tooltip-props.spec.js (2)

185-197: LGTM! The test case correctly validates the disableTooltip prop when it returns true.

The test ensures that the tooltip is not rendered when disableTooltip returns true.


199-214: LGTM! The test case correctly validates the disableTooltip prop when it returns false.

The test ensures that the tooltip is rendered when disableTooltip returns false.

docs/docs/options.mdx (1)

130-130: LGTM! The documentation clearly explains the disableTooltip property.

The documentation correctly describes the new disableTooltip property and its usage.

@nareshpingale
Copy link
Contributor Author

  • Added tests for disableTooltip returning true and false
  • Addressed formatting issue raised by @danielbarion
  • Added disableTooltip check to anchorById
  • Added disableTooltip in options in docs, although wasn't able to verify this as there is a peer dependency error by our docusaurus version for react 18

Copy link
Member

@gabrieljablonski gabrieljablonski left a comment

Choose a reason for hiding this comment

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

LGTM. Possibly merging sometime next week.

@gabrieljablonski gabrieljablonski added the Awaiting merge Issue is fixed on a PR that will me merged soon. label Aug 1, 2024
@gabrieljablonski gabrieljablonski merged commit 0776637 into ReactTooltip:master Aug 4, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting merge Issue is fixed on a PR that will me merged soon. Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT REQ] Dynamic callback for disabling tooltip
3 participants