fast icon indicating copy to clipboard operation
fast copied to clipboard

Feat: avoid multiple tooltips showing up simultaneously

Open scomea opened this issue 1 year ago • 2 comments

📖 Description

The current tooltip behavior can show multiple tooltips at the same time, most commonly a tooltip that shows because an element has been focused remains visible when another element is hovered. Or a hovered tooltip remains visible as the user tabs to other controls.

After this change an active tooltip monitors mouse movement and focus changes as the document level so a hover driven tooltip is dismissed when another element is focused, and a focus driven tooltip is dismissed when the mouse moves.

Also ensured we removed listeners on disconnect.

🎫 Issues

Multiple user focus driven tooltips can show up simultaneously and could easily overlap:

image

✅ Checklist

General

  • [x] I have included a change request file using $ yarn change
  • [x] I have added tests for my changes.
  • [x] I have tested my changes.
  • [ ] I have updated the project documentation to reflect my changes.
  • [x] I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

scomea avatar Apr 09 '24 23:04 scomea

I think the current implementation is worth keeping alongside this new behavior.

as implementation goes, aiming at only having one tooltip displayed at a time could be achieved without resorting to add new listeners in each instance and simply keep one reference at class level.

e.g.,

static currentTooltipInstance: Tooltip | null = null;

then, at the start of showTooltip add

if (Tooltip.currentTooltipInstance !== this && Tooltip.currentTooltipInstance?.hideTooltip)
	Tooltip.currentTooltipInstance.hideTooltip();
Tooltip.currentTooltipInstance = this;

olaf-k avatar Apr 10 '24 13:04 olaf-k

I think the current implementation is worth keeping alongside this new behavior.

as implementation goes, aiming at only having one tooltip displayed at a time could be achieved without resorting to add new listeners in each instance and simply keep one reference at class level.

e.g.,

static currentTooltipInstance: Tooltip | null = null;

then, at the start of showTooltip add

if (Tooltip.currentTooltipInstance !== this && Tooltip.currentTooltipInstance?.hideTooltip)
	Tooltip.currentTooltipInstance.hideTooltip();
Tooltip.currentTooltipInstance = this;

Not convinced about keeping the old behavior as I think it is provably broken with the overlapping cases. The static prop is a good idea and much leaner, will give it a go. (worked!)

scomea avatar Apr 10 '24 13:04 scomea

We're avoiding feature work for now due to closing out of #6951, I do think this is a good addition we're just focused on fixes as part of our strategy to close out the work on foundation.

janechu avatar Jun 14 '24 17:06 janechu