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

Add mouseover and mouseout as default events #1194

Merged
merged 4 commits into from
Jun 16, 2024

Conversation

gabrieljablonski
Copy link
Member

@gabrieljablonski gabrieljablonski commented Jun 6, 2024

Closes #1193

See this demo for explanation. mouseover and mouseout apply to a wider range of scenarios, more specifically when dealing with nested tooltip anchors.

mouseenter and mouseleave should still be present for backwards compatibility. But should we deprecate it and remove it on v6? Keeping it seems fine for more functionality, but will likely almost never be used.

This will not impact current behavior for "regular" tooltip usage (no nested anchor elements).

Summary by CodeRabbit

  • New Features

    • Enhanced Tooltip component with new event handling options including mouseover and mouseout.
  • Bug Fixes

    • Improved precision in managing tooltip open and close events.
  • Documentation

    • Updated Tooltip component documentation to reflect new event handling options and deprecated props.

Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

The changes update the Tooltip component in a React application to enhance event handling and refine prop management. Deprecated props are removed, default event values are adjusted, and new global close events are added. These modifications improve tooltip behavior, especially for nested elements, ensuring tooltips update correctly when moving between parent and child elements.

Changes

File Change Summary
docs/docs/options.mdx Updated Tooltip props, deprecated certain props, adjusted default values, added global close events.
src/components/Tooltip/Tooltip.tsx Modified event handling logic, updated event types, added new event options.
src/components/Tooltip/TooltipTypes.d.ts Added mouseover and mouseout events to AnchorOpenEvents and AnchorCloseEvents.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Handle nested elements with tooltips (#1193)

Poem

In the world of code, where tooltips play,
Events now guide them in a smoother way.
From mouseover to mouseout they glide,
Nested elements no longer collide.
So here's a cheer for tooltips bright,
Enhancing our apps, day and night! 🌟🖱️


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 Configration 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

github-actions bot commented Jun 6, 2024

Beta version released with the last commit 🚀

or

npm install [email protected]

@@ -88,13 +88,15 @@ export interface TooltipRefProps {
export type AnchorOpenEvents = {
mouseenter?: boolean
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we deprecate mouseenter and mouseleave?

Keeping them seems fine, but with mouseover/mouseout, would they ever really be useful?

Copy link
Member

Choose a reason for hiding this comment

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

What will be the benefits to keep and to remove?

Copy link
Member Author

@gabrieljablonski gabrieljablonski Jun 6, 2024

Choose a reason for hiding this comment

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

I honestly can't think of any realistic situation mouseenter/mouseleave (1) would solve something that mouseover/mouseout (2) doesn't.

The only issue with (2) is that we're triggering sequential hide/show state updates on the tooltip every time the user hovers between the nested element and the parent element. I couldn't visually notice any bad behavior due to this, but it's something to keep in mind.

Maybe we just leave (1) as the default, and have (2) + a troubleshooting page for people having issues with nested anchor elements?

Furthermore, maybe a more robust approach would be to forget about (2) and handle nested elements explicitly (use DOM element contains() method)?

There's a few different approaches we can take here. We can come back to this discussion later.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, about removing it: if it's not causing any bug, I would like to keep it so we support those events.

About the contains(), I like the idea

Copy link

github-actions bot commented Jun 6, 2024

Beta version released with the last commit 🚀

or

npm install [email protected]

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 e59397c and 62e7a64.

Files selected for processing (3)
  • docs/docs/options.mdx (1 hunks)
  • src/components/Tooltip/Tooltip.tsx (4 hunks)
  • src/components/Tooltip/TooltipTypes.d.ts (1 hunks)
Additional context used
LanguageTool
docs/docs/options.mdx

[uncategorized] ~95-~95: You might be missing the article “the” here. (AI_EN_LECTOR_MISSING_DETERMINER_THE)
Context: ... | Class name to customize tooltip arrow element. You can also use the def...


[uncategorized] ~107-~107: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | hover | hover click ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnEsc | boolean ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnEsc | boolean | no | ~...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnEsc | boolean | no | false ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | ~~Pressing escape key will close the t...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnScroll | boolean ...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnScroll | boolean | no | ~...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnScroll | boolean | no | false ...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | Scrolling will close the tooltip <...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnResize | boolean ...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnResize | boolean | no | ~...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnResize | boolean | no | false ...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | ~~Resizing the window will close the t...


[typographical] ~126-~126: Consider adding a comma. (IF_THEN_COMMA)
Context: ...own by default, if false or not provided then it's in hidden state by default. | | ...

Biome
src/components/Tooltip/Tooltip.tsx

[error] 867-867: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 868-868: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 874-874: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 875-875: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 899-899: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 900-900: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 902-902: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 222-222: This hook does not specify all of its dependencies: afterHide (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 222-222: This hook does not specify all of its dependencies: afterShow (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 412-412: This hook does not specify all of its dependencies: border (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 412-412: This hook does not specify all of its dependencies: handleTooltipPosition (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.


[error] 412-412: This hook specifies more dependencies than necessary: show, content, externalStyles (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.


[error] 412-412: This hook does not specify all of its dependencies: handleComputedPosition (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 412-412: This hook does not specify all of its dependencies: middlewares (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 469-469: This hook does not specify all of its dependencies: actualCloseEvents (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 469-469: This hook does not specify all of its dependencies: actualGlobalCloseEvents.escape (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.


[error] 469-469: This hook does not specify all of its dependencies: anchorId (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 469-469: This hook does not specify all of its dependencies: handleShow (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.


[error] 469-469: This hook specifies more dependencies than necessary: rendered, openEvents, closeEvents, globalCloseEvents, shouldOpenOnClick, delayShow, delayHide (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.

This dependency can be removed from the list.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.

Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.


[error] 469-469: This hook does not specify all of its dependencies: show (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

Additional comments not posted (4)
src/components/Tooltip/TooltipTypes.d.ts (2)

91-91: LGTM! The addition of mouseover to AnchorOpenEvents aligns with the PR's objectives.


99-99: LGTM! The addition of mouseout to AnchorCloseEvents aligns with the PR's objectives.

docs/docs/options.mdx (1)

91-135: LGTM! The documentation updates accurately reflect the changes in the Tooltip component's behavior and properties.

Tools
LanguageTool

[uncategorized] ~95-~95: You might be missing the article “the” here. (AI_EN_LECTOR_MISSING_DETERMINER_THE)
Context: ... | Class name to customize tooltip arrow element. You can also use the def...


[uncategorized] ~107-~107: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | hover | hover click ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnEsc | boolean ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnEsc | boolean | no | ~...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnEsc | boolean | no | false ...


[uncategorized] ~116-~116: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | ~~Pressing escape key will close the t...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnScroll | boolean ...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnScroll | boolean | no | ~...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnScroll | boolean | no | false ...


[uncategorized] ~117-~117: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | Scrolling will close the tooltip <...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnResize | boolean ...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | | closeOnResize | boolean | no | ~...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...closeOnResize | boolean | no | false ...


[uncategorized] ~118-~118: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ... | true false | ~~Resizing the window will close the t...


[typographical] ~126-~126: Consider adding a comma. (IF_THEN_COMMA)
Context: ...own by default, if false or not provided then it's in hidden state by default. | | ...

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

Line range hint 105-134: LGTM! The updates to the Tooltip component's event handling logic align with the PR's objectives and are well-implemented.

@gabrieljablonski gabrieljablonski merged commit 193b3b4 into master Jun 16, 2024
7 checks passed
@gabrieljablonski gabrieljablonski deleted the feat/add-mouseover-mouseout-events branch June 16, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested elements with tooltip
2 participants