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

fix: Tooltip: Don't close if user hovers on opener then tooltip content #5320

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

margaree
Copy link
Contributor

@margaree margaree commented Jan 16, 2025

Jira ticket

See here to test out

A user should be able to go back and forth (hovering) between tooltip opener and content. Previously the tooltip would close as soon as the mouse left the opener. This is a WCAG violation (see ticket for more details).

Ideally the gap between the opener and tooltip (the offset) would be a hover zone but I was unable to get that working in a way that wasn't overly complex given the complexity of tooltip positioning.

This implementation uses a timeout to delay the closing. Jeff and I both felt like the 100ms time was a good balance of enough time for a user to generally get to the tooltip without being detectable on actual close.

This should be fine in general usecases (though let me know if there's something I'm missing). There could be some issues if something weird is being done with offset. I was able to go between opener and tooltip with larger offsets, but someone with low dexterity could have problems, so if those cases come up then we should dig into those more.

Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-5320/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@@ -449,6 +449,9 @@ class Tooltip extends RtlMixin(LitElement) {
this._isHovering = false;
this._resizeRunSinceTruncationCheck = false;
this._viewportMargin = defaultViewportMargin;

this.#isHoveringTooltip = false;
this.#leftTooltip = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open to a better name for this

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm yeah, I can see it being a little confusing. Idk, maybe mouseLeftTooltip would be a bit clearer. Or perhaps wasHoveringTooltip, or mouseLeavingTooltip?

@margaree margaree changed the title [ignore for now] fix: Tooltip: Don't close if user hovers on opener then tooltip content fix: Tooltip: Don't close if user hovers on opener then tooltip content Jan 17, 2025
@margaree margaree marked this pull request as ready for review January 17, 2025 19:38
@margaree margaree requested a review from a team as a code owner January 17, 2025 19:38
@@ -855,7 +867,7 @@ class Tooltip extends RtlMixin(LitElement) {
_onTargetMouseLeave() {
clearTimeout(this._hoverTimeout);
this._isHovering = false;
this._updateShowing();
setTimeout(this._updateShowing.bind(this), 100); // delay to allow for mouseenter to fire if hovering on tooltip
Copy link
Member

Choose a reason for hiding this comment

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

Nit: arrow functions allow you to avoid bind

Suggested change
setTimeout(this._updateShowing.bind(this), 100); // delay to allow for mouseenter to fire if hovering on tooltip
setTimeout(() => this._updateShowing(), 100); // delay to allow for mouseenter to fire if hovering on tooltip

setTimeout(() => {
this.#leftTooltip = false;
this._updateShowing();
}, 100); // delay to allow for mouseenter to fire if hovering on target
Copy link
Member

Choose a reason for hiding this comment

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

Is there a weird race condition if they leave but then come back and leave again within this time period? Might be more obvious if you increase it to like 10s while testing. If this is a problem, you could capture the timeout identifier (the thing returned from setTimeout) and cancel the previous one using clearTimeout.

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.

3 participants