-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
New props for selecting events to open/close the tooltip #1108
Conversation
const shouldOpenOnClick = openOnClick || events.includes('click') | ||
const hasClickEvent = | ||
shouldOpenOnClick || openEvents?.click || openEvents?.dblclick || openEvents?.mousedown | ||
const actualOpenEvents: AnchorOpenEvents = openEvents | ||
? { ...openEvents } | ||
: { | ||
mouseenter: true, | ||
focus: true, | ||
click: false, | ||
dblclick: false, | ||
mousedown: false, | ||
} | ||
if (!openEvents && shouldOpenOnClick) { | ||
Object.assign(actualOpenEvents, { | ||
mouseenter: false, | ||
focus: false, | ||
click: true, | ||
}) | ||
} | ||
const actualCloseEvents: AnchorCloseEvents = closeEvents | ||
? { ...closeEvents } | ||
: { | ||
mouseleave: true, | ||
blur: true, | ||
click: false, | ||
} | ||
if (!closeEvents && shouldOpenOnClick) { | ||
Object.assign(actualCloseEvents, { | ||
mouseleave: false, | ||
blur: false, | ||
}) | ||
} | ||
const actualGlobalCloseEvents: GlobalCloseEvents = globalCloseEvents | ||
? { ...globalCloseEvents } | ||
: { | ||
escape: closeOnEsc || false, | ||
scroll: closeOnScroll || false, | ||
resize: closeOnResize || false, | ||
clickOutsideAnchor: hasClickEvent || false, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may look a little confusing at first, but it ensures openOnClick
and the deprecated events
props still work exactly as before.
if (!closeEvents && shouldOpenOnClick) { | ||
Object.assign(actualCloseEvents, { | ||
mouseleave: false, | ||
blur: false, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openOnClick
works as a shorthand for
<Tooltip
openEvents={{ click: true }}
closeEvents={{}}
/>
Without setting closeEvents
, the tooltip would keep the default behavior of closing on mouseleave
/blur
, which feels cumbersome for this simple use-case. So deprecating openOnClick
seems like a bad idea.
<p>This PR was automatically created by Snyk using the credentials of a real user.</p><br /><h3>Snyk has created this PR to upgrade react-tooltip from 5.21.6 to 5.22.0.</h3> :information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project. <hr/> - The recommended version is **9 versions** ahead of your current version. - The recommended version was released **22 days ago**, on 2023-11-01. <details> <summary><b>Release notes</b></summary> <br/> <details> <summary>Package name: <b>react-tooltip</b></summary> <ul> <li> <b>5.22.0</b> - <a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/releases/tag/v5.22.0">2023-11-01</a></br><p>If you like the project, please give the project a GitHub 🌟</p> <h2>What's Changed</h2> <ul> <li>Fade-out transition when closing the tooltip by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1969455674" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1106" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1106/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1106">#1106</a> <ul> <li>See <a href="https://react-tooltip.com/docs/examples/styling#customizing-openingclosing-animation" rel="nofollow">docs</a> for details</li> </ul> </li> <li>New props for selecting events to open/close the tooltip by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1970604025" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1108" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1108/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1108">#1108</a> <ul> <li>See <a href="https://react-tooltip.com/docs/options#:~:text=Use%20globalCloseEvents%20instead.-,openEvents,-Record%3Cstring%2C%20boolean" rel="nofollow">docs</a> for details</li> </ul> </li> </ul> <p><strong>Full Changelog</strong>: <a class="commit-link" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/compare/v5.21.7...v5.22.0"><tt>v5.21.7...v5.22.0</tt></a></p> </li> <li> <b>5.22.0-beta.1109.1</b> - 2023-11-01 </li> <li> <b>5.22.0-beta.1109.0</b> - 2023-10-31 </li> <li> <b>5.22.0-beta.1108.0</b> - 2023-10-31 </li> <li> <b>5.22.0-beta.1106.0</b> - 2023-10-31 </li> <li> <b>5.22.0-beta.1091.1</b> - 2023-09-14 </li> <li> <b>5.22.0-beta.1091.0</b> - 2023-09-14 </li> <li> <b>5.21.7</b> - <a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/releases/tag/v5.21.7">2023-11-01</a></br><p>If you like the project, please give the project a GitHub 🌟</p> <h2>What's Changed</h2> <ul> <li>Fix anchor on DOM change by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1971537380" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1110" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1110/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1110">#1110</a></li> </ul> <p><strong>Full Changelog</strong>: <a class="commit-link" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/compare/v5.21.6...v5.21.7"><tt>v5.21.6...v5.21.7</tt></a></p> </li> <li> <b>5.21.7-beta.1110.0</b> - 2023-11-01 </li> <li> <b>5.21.6</b> - <a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/releases/tag/v5.21.6">2023-10-24</a></br><p>If you like the project, please give the project a GitHub 🌟</p> <h2>What's Changed</h2> <ul> <li>Tiered sponsors by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1924583073" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1099" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1099/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1099">#1099</a></li> <li>README admonition by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1936493747" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1101" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1101/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1101">#1101</a></li> <li>Fix <code>anchorsBySelect</code> ref leak by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gabrieljablonski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://snyk.io/redirect/github/gabrieljablonski">@ gabrieljablonski</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1896963156" data-permission-text="Title is private" data-url="ReactTooltip/react-tooltip#1091" data-hovercard-type="pull_request" data-hovercard-url="/ReactTooltip/react-tooltip/pull/1091/hovercard" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/pull/1091">#1091</a></li> </ul> <p><strong>Full Changelog</strong>: <a class="commit-link" href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/compare/v5.21.5...v5.21.6"><tt>v5.21.5...v5.21.6</tt></a></p> </li> </ul> from <a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/releases">react-tooltip GitHub release notes</a> </details> </details> <details> <summary><b>Commit messages</b></summary> </br> <details> <summary>Package name: <b>react-tooltip</b></summary> <ul> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/dd53fa13326d8f09626512e50002dae1368dd3c8">dd53fa1</a> docs: open/close events</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/9e5d2f74baf25336acd75076a14b98181c90592a">9e5d2f7</a> docs: improve options table spacing</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/8e786af177d69d6d96021e990a32451ce44593da">8e786af</a> feat: open/close events</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/bd5fddfb12a91c6dd4fa1892760138b8530c4e9d">bd5fddf</a> docs: typo</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/a24ec2f8b3b8b393ba8a74c13d85c8520594bb65">a24ec2f</a> docs: tooltip closing transition</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/c645ce701bf3ede3b2090a81d3c20e635c87f0a7">c645ce7</a> feat: tooltip closing transition</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/9b03e2c0fef966bc727f34117fe1f8b1bb7935c1">9b03e2c</a> chore(version): v5.21.7</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/86a9fe4c5e3d329c1062a902f305ae14e3737603">86a9fe4</a> fix: anchor filter on dom change</li> <li><a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/commit/d7f98e82f73b9eec92c80f01d4b73a176e5656a9">d7f98e8</a> docs: readme sponsorship banner width</li> </ul> <a href="https://snyk.io/redirect/github/ReactTooltip/react-tooltip/compare/3812314430666172a268d277e1f731584c58885d...dd53fa13326d8f09626512e50002dae1368dd3c8">Compare</a> </details> </details> <hr/> **Note:** *You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.* For more information: <img src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiJiNmE1NDNhZS05MDhjLTRiNTAtYjE4ZS02NTUxZDljYmY3MmIiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6ImI2YTU0M2FlLTkwOGMtNGI1MC1iMThlLTY1NTFkOWNiZjcyYiJ9fQ==" width="0" height="0"/> 🧐 [View latest project report](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763?utm_source=github&utm_medium=referral&page=upgrade-pr) 🛠 [Adjust upgrade PR settings](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763/settings/integration?pkg=react-tooltip&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) <!--- (snyk:metadata:{"prId":"b6a543ae-908c-4b50-b18e-6551d9cbf72b","prPublicId":"b6a543ae-908c-4b50-b18e-6551d9cbf72b","dependencies":[{"name":"react-tooltip","from":"5.21.6","to":"5.22.0"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"98480bdc-d80b-4fd1-89d7-c4c56a706763","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":9,"publishedDate":"2023-11-01T20:36:48.347Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":false,"isBreakingChange":false,"priorityScoreList":[]}) ---> Co-authored-by: snyk-bot <[email protected]>
Closes #1072.
Beta version
[email protected]