Skip to content

Comments

use Floating UI for tooltip#6468

Merged
radium-v merged 4 commits intomasterfrom
users/jokreitl/use-floatingui-for-tooltip
Dec 10, 2022
Merged

use Floating UI for tooltip#6468
radium-v merged 4 commits intomasterfrom
users/jokreitl/use-floatingui-for-tooltip

Conversation

@radium-v
Copy link
Collaborator

@radium-v radium-v commented Oct 24, 2022

Pull Request

📖 Description

  • Rewrites the Tooltip component to use Floating UI.
  • Enables built-in aria-describedby support. Once the anchor element is resolved, the aria-describedby attribute will be added to it to match the tooltip's id. If the anchor changes, the id will be removed from the old anchor's aria-describedby attribute and added to the new anchor.
  • Replaces the position attribute with placement to match the naming convention used by Floating UI.
  • Adds the show attribute to control the visibility of the tooltip.
  • Removes the delay attribute as it's no longer needed - tooltip transitions can be controlled via CSS.
  • Updates the spec document to reflect the changes.
  • Adds a nullalbleBooleanConverter to @microsoft/fast-element for attributes that are true, false, or undefined

🎫 Issues

👩‍💻 Reviewer Notes

The id property is now decorated with the @observable decorator, to allow the component to update the aria-describedby attribute accordingly. Since this is a built-in property, I don't know if or how that may be treated in comparison to a custom property.

📑 Test Plan

All tests for the tooltip component should pass as expected.

✅ Checklist

General

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

Component-specific

@radium-v radium-v self-assigned this Oct 24, 2022
@radium-v radium-v changed the title Users/jokreitl/use floatingui for tooltip use Floating UI for tooltip Oct 24, 2022
@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch from c7c1671 to a0c8649 Compare October 25, 2022 19:25
@radium-v radium-v changed the base branch from users/jokreitl/use-floatingui-for-select to master October 25, 2022 19:25
@radium-v radium-v marked this pull request as ready for review October 25, 2022 19:27
@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch from a0c8649 to 7573023 Compare October 25, 2022 20:34
@github-actions
Copy link

github-actions bot commented Oct 25, 2022

📊 Tachometer Benchmark Results

Summary

clickTrigger10x

  • repeat-basic-splice-itemCount=1000&deleteCount=20&addCount=20: slower ❌ 5% - 54% (5.04ms - 29.49ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-push-itemCount=100&addCount=20: unsure 🔍 -0% - +1% (-0.57ms - +2.02ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-reverse-itemCount=100: unsure 🔍 -1% - +1% (-4.03ms - +2.60ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-shift-itemCount=100: unsure 🔍 -0% - +1% (-0.98ms - +2.38ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-unshift-itemCount=100&addCount=20: unsure 🔍 -2% - +1% (-5.97ms - +3.96ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

create10k

  • render-create10k: unsure 🔍 -1% - +1% (-1.91ms - +1.74ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

createDelete5x

  • render-createDelete5x: unsure 🔍 -2% - +2% (-9.68ms - +11.05ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

runFile1k

  • observable-runFile1k: unsure 🔍 -9% - +18% (-0.98ms - +1.91ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

update10th

  • render-update10th: unsure 🔍 -2% - +0% (-2.77ms - +0.76ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

usedJSHeapSize

  • observable-runFile1k: unsure 🔍 -1% - +0% (-0.33ms - +0.21ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • render-create10k: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • render-createDelete5x: unsure 🔍 -0% - +0% (-0.08ms - +0.06ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • render-update10th: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-basic-splice-itemCount=1000&deleteCount=20&addCount=20: faster ✔ 0% - 2% (0.18ms - 0.80ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-push-itemCount=100&addCount=20: unsure 🔍 -0% - -0% (-0.09ms - -0.00ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-reverse-itemCount=100: unsure 🔍 -0% - +1% (-0.13ms - +0.33ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-shift-itemCount=100: unsure 🔍 -0% - +0% (-0.06ms - +0.03ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary
  • repeat-nested-unshift-itemCount=100&addCount=20: unsure 🔍 -0% - +0% (-0.02ms - +0.08ms)
    users/jokreitl/use-floatingui-for-tooltip vs master Customize summary

Results

observable-runFile1k

runFile1k

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master9.72ms - 11.73ms-unsure 🔍
-17% - +9%
-1.91ms - +0.98ms
users/jokreitl/use-floatingui-for-tooltip10.15ms - 12.22msunsure 🔍
-9% - +18%
-0.98ms - +1.91ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master48.33ms - 48.70ms-unsure 🔍
-0% - +1%
-0.21ms - +0.33ms
users/jokreitl/use-floatingui-for-tooltip48.26ms - 48.64msunsure 🔍
-1% - +0%
-0.33ms - +0.21ms
-
render-create10k

create10k

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master190.25ms - 192.56ms-unsure 🔍
-1% - +1%
-1.74ms - +1.91ms
users/jokreitl/use-floatingui-for-tooltip189.91ms - 192.72msunsure 🔍
-1% - +1%
-1.91ms - +1.74ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master46.98ms - 46.99ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
users/jokreitl/use-floatingui-for-tooltip46.98ms - 46.99msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
render-createDelete5x

createDelete5x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master475.42ms - 491.02ms-unsure 🔍
-2% - +2%
-11.05ms - +9.68ms
users/jokreitl/use-floatingui-for-tooltip477.09ms - 490.73msunsure 🔍
-2% - +2%
-9.68ms - +11.05ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master53.79ms - 53.89ms-unsure 🔍
-0% - +0%
-0.06ms - +0.08ms
users/jokreitl/use-floatingui-for-tooltip53.77ms - 53.87msunsure 🔍
-0% - +0%
-0.08ms - +0.06ms
-
render-update10th

update10th

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master168.99ms - 171.54ms-unsure 🔍
-0% - +2%
-0.76ms - +2.77ms
users/jokreitl/use-floatingui-for-tooltip168.03ms - 170.49msunsure 🔍
-2% - +0%
-2.77ms - +0.76ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master46.98ms - 46.99ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
users/jokreitl/use-floatingui-for-tooltip46.98ms - 46.99msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
repeat-basic-splice-itemCount=1000&deleteCount=20&addCount=20

clickTrigger10x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master49.18ms - 67.25ms-faster ✔
8% - 38%
5.04ms - 29.49ms
users/jokreitl/use-floatingui-for-tooltip67.24ms - 83.72msslower ❌
5% - 54%
5.04ms - 29.49ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master46.83ms - 47.28ms-slower ❌
0% - 2%
0.18ms - 0.80ms
users/jokreitl/use-floatingui-for-tooltip46.35ms - 46.78msfaster ✔
0% - 2%
0.18ms - 0.80ms
-
repeat-nested-push-itemCount=100&addCount=20

clickTrigger10x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master221.15ms - 222.64ms-unsure 🔍
-1% - +0%
-2.02ms - +0.57ms
users/jokreitl/use-floatingui-for-tooltip221.57ms - 223.68msunsure 🔍
-0% - +1%
-0.57ms - +2.02ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master51.84ms - 51.88ms-unsure 🔍
+0% - +0%
+0.00ms - +0.09ms
users/jokreitl/use-floatingui-for-tooltip51.78ms - 51.85msunsure 🔍
-0% - -0%
-0.09ms - -0.00ms
-
repeat-nested-reverse-itemCount=100

clickTrigger10x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master399.70ms - 404.18ms-unsure 🔍
-1% - +1%
-2.60ms - +4.03ms
users/jokreitl/use-floatingui-for-tooltip398.79ms - 403.66msunsure 🔍
-1% - +1%
-4.03ms - +2.60ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master56.95ms - 57.27ms-unsure 🔍
-1% - +0%
-0.33ms - +0.13ms
users/jokreitl/use-floatingui-for-tooltip57.05ms - 57.38msunsure 🔍
-0% - +1%
-0.13ms - +0.33ms
-
repeat-nested-shift-itemCount=100

clickTrigger10x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master245.65ms - 246.67ms-unsure 🔍
-1% - +0%
-2.38ms - +0.98ms
users/jokreitl/use-floatingui-for-tooltip245.26ms - 248.46msunsure 🔍
-0% - +1%
-0.98ms - +2.38ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master51.80ms - 51.86ms-unsure 🔍
-0% - +0%
-0.03ms - +0.06ms
users/jokreitl/use-floatingui-for-tooltip51.79ms - 51.85msunsure 🔍
-0% - +0%
-0.06ms - +0.03ms
-
repeat-nested-unshift-itemCount=100&addCount=20

clickTrigger10x

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master374.23ms - 381.27ms-unsure 🔍
-1% - +2%
-3.96ms - +5.97ms
users/jokreitl/use-floatingui-for-tooltip373.23ms - 380.25msunsure 🔍
-2% - +1%
-5.97ms - +3.96ms
-

usedJSHeapSize

VersionAvg timevs mastervs users/jokreitl/use-floatingui-for-tooltip
master51.76ms - 51.84ms-unsure 🔍
-0% - +0%
-0.08ms - +0.02ms
users/jokreitl/use-floatingui-for-tooltip51.81ms - 51.87msunsure 🔍
-0% - +0%
-0.02ms - +0.08ms
-

tachometer-reporter-action v2 for Validate Benchmarks

@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch 3 times, most recently from 836da95 to b047c0a Compare October 27, 2022 20:55
Copy link
Contributor

@EisenbergEffect EisenbergEffect left a comment

Choose a reason for hiding this comment

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

Looks much simpler. I agree, I'm not sure about patching id in this way...but if it's working cross-browser and there are no a11y issues then it's probably ok. I've seen much crazier things done.

@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch from b047c0a to 5b20318 Compare November 14, 2022 20:47
@yinonov
Copy link
Contributor

yinonov commented Nov 15, 2022

  1. should show be public? tooltip open state should probably not be triggered manually by authors, right?
  2. authors occasionally set tooltips on non-focusable elements with the assumption mouse hovering interaction is sufficient. now that ergonomics is featured in tooltip and adds an recommended aria-describedby pattern, should it also apply a tabindex to anchor when non-focusable?

Comment on lines +35 to +37
<fast-button id="${x => x.anchor}">
${x => x.buttonContent ?? "Hover or focus me"}
</fast-button>
Copy link
Member

Choose a reason for hiding this comment

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

This is a good example as I think it illustrates an issue we currently have with cross-root ARIA for Button and similar components which delegate focus. While the tooltip shows up, it's not announced, which means that (to my knowledge) aria-describedby isn't working since the two id's are in separate DOM's.

Copy link
Member

Choose a reason for hiding this comment

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

TLDR, we need to review if we either can figure out a way to manage this issue or if we should shift how we approach components which currently delegate focus.

@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch from 5b20318 to 64e288c Compare December 9, 2022 21:46
@chrisdholt
Copy link
Member

  1. should show be public? tooltip open state should probably not be triggered manually by authors, right?
  2. authors occasionally set tooltips on non-focusable elements with the assumption mouse hovering interaction is sufficient. now that ergonomics is featured in tooltip and adds an recommended aria-describedby pattern, should it also apply a tabindex to anchor when non-focusable?

Thinking about 2 above more, I think we likely should avoid forcing non-focusable elements to be focusable - in many cases, if the tooltip is applied to something like an image, or other non-interactive element, the tabindex would create an issue. Further, focus isn't required to have tooltips read out, it's simply a common pattern to add them to interactive elements. In the case an element should be focusable and it's not, I think it's probably best to leave that to authors.

@radium-v radium-v force-pushed the users/jokreitl/use-floatingui-for-tooltip branch from 64e288c to 6a3820c Compare December 9, 2022 23:51
@radium-v radium-v merged commit 555f1b2 into master Dec 10, 2022
@radium-v radium-v deleted the users/jokreitl/use-floatingui-for-tooltip branch December 10, 2022 00:03
@yinonov
Copy link
Contributor

yinonov commented Dec 10, 2022

  1. should show be public? tooltip open state should probably not be triggered manually by authors, right?
  2. authors occasionally set tooltips on non-focusable elements with the assumption mouse hovering interaction is sufficient. now that ergonomics is featured in tooltip and adds an recommended aria-describedby pattern, should it also apply a tabindex to anchor when non-focusable?

Thinking about 2 above more, I think we likely should avoid forcing non-focusable elements to be focusable - in many cases, if the tooltip is applied to something like an image, or other non-interactive element, the tabindex would create an issue. Further, focus isn't required to have tooltips read out, it's simply a common pattern to add them to interactive elements. In the case an element should be focusable and it's not, I think it's probably best to leave that to authors.

@chrisdholt you mind sharing more on why "focus isn't required to have tooltips read out"? can tooltips still get picked up by ATs then?

janechu pushed a commit that referenced this pull request Jun 10, 2024
* add nullableBooleanConverter for attributes

* remove tooltip options from dom-shim spec

* rewrite tooltip to use floating-ui

* Change files
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.

4 participants