+
Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Conversation

clintcs
Copy link
Collaborator

@clintcs clintcs commented Aug 14, 2024

🚀 Description

  • Gave Tooltip a treatment similar to Menu, which let me get rid the last instance of setContainingBlock. It also fixed a couple outstanding bugs where Tooltip wasn't escaping its container.
  • Fixed an unrelated bug.
  • Swapped out the CSS arrow for SVGs to better match the mockups.
  • Tweaked spacing between the arrow and Tooltip's target.

📋 Checklist

  • I have read and followed the Contributing Guidelines.
  • I have added tests to cover new or updated functionality.
  • I have created or updated stories in Storybook to document the new functionality.
  • I have included a changeset with this Pull Request if it adds/updates/removes functionality for consumers.
  • I have scheduled a Design Review for these changes, if one is required.
  • I have followed the ARIA Authoring Practices Guide and/or met with the Accessibility Team to ensure this functionality is accessible.

🔬 How to Test

@mayuri-todkar tested this against a few applications (🙏). However, if you want to test a reproduction:

  1. Navigate to the Modal (With Tertiary Content Icon) story.
  2. Open Modal.
  3. Hover over the information icon.
  4. Make sure Tooltip breaks out of Modal.
  5. Probably also worth navigating to Tooltip and checking each placement.

📸 Images/Videos of Functionality

Before

image

After

image

Copy link

changeset-bot bot commented Aug 14, 2024

🦋 Changeset detected

Latest commit: 4554cf0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@crowdstrike/glide-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@clintcs clintcs changed the title Switch tooltip to popover Use popover with Tooltip Aug 14, 2024
Copy link
Contributor

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch 4 times, most recently from ba46889 to 85272af Compare August 15, 2024 02:28
@state()
private effectivePlacement: Placement = this.placement ?? 'bottom';

#arrowElementRef = createRef<HTMLDivElement>();
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

HTMLDivElement and HTMLSpanElement don't give us any special properties—and they make markup changes prone to unnecessary typechecking failures. I can't see a good use for them. Anyone else feel the same?

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch from 85272af to 9b34405 Compare August 15, 2024 12:57
src/tooltip.ts Outdated
strategy: 'fixed',
middleware: [
offset(6),
offset(4),
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

From Design.

src/tooltip.ts Outdated
shift(),
arrow({ element: arrowElement }),
shift({
limiter: limitShift({
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

Before

image

After

image

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch 4 times, most recently from bcf6370 to 349d66e Compare August 15, 2024 14:39
@clintcs clintcs force-pushed the switch-tooltip-to-popover branch from 349d66e to 3721c4c Compare August 15, 2024 15:08
}
:host {
display: inline-block;
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

Added this after debugging some tests. It cleans up our tests and is probably a better default for consumers who aren't using display: flex. Yeah?

Before

image

After

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah!

top: arrowY === null ? '' : `${arrowY}px`,
right: '',
bottom: '',
[staticSide]: '-3px',
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

staticSide is no longer needed now that we're using an exact-size SVG instead of a box, which needed to be offset by half its height.

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch 5 times, most recently from 19ee16c to cb77a42 Compare August 15, 2024 16:16
src/tooltip.ts Outdated
}

#hide() {
this.#cleanUpFloatingUi?.();
Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

Halp! I can't seem to get coverage on this. Any ideas? It's called multiple times in tests. I'm not even sure what it means 😆.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue goes away if I switch #hide to private hide. Not great. But it's something. I'd leave a comment linking this comment.

I'll keep looking for a better solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also does the trick:

if (this.#cleanUpFloatingUi) {
  this.#cleanUpFloatingUi();
}

Very silly. I'll push the above with a comment before merging.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If no one else has any ideas, I can pull this branch down tomorrow AM and give it a look

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No worries. I suspect it's just an optional chaining bug deep in the bowels of Istanbul or wherever.

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch 3 times, most recently from c67d9fb to 80f8a7b Compare August 15, 2024 16:55
data-test="arrow"
${ref(this.#arrowElementRef)}
>
${choose(this.effectivePlacement, [
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

choose is a thing!

Copy link
Collaborator

Choose a reason for hiding this comment

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

fancy!

@clintcs clintcs force-pushed the switch-tooltip-to-popover branch from 80f8a7b to 1f87efe Compare August 15, 2024 16:58
@clintcs clintcs marked this pull request as ready for review August 15, 2024 17:01
Copy link
Collaborator

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! This is great.


I noticed one small bug with the private-label stuff I think:

Screen.Recording.2024-08-15.at.1.56.06.PM.mov

export default [
css`
@keyframes animate-tooltip {
@keyframes tooltip {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dig dropping the animate- prefix for keyframes 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice. I figured "animate" is implied—both here and when it's use with animation.

}
:host {
display: inline-block;
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah!

Comment on lines +84 to +88
A simple "transform" could replace Floating UI for the arrow if not for a Chrome
bug with "popover" when "scale()" is animated on the popover or a container within
it. With "transform" on the arrow, the arrow is initially offset by a couple pixels
before landing in the correct position when the animation finishes. It only happens
when the tooltip is left or right of its target.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very annoying, thanks for the comments here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

100%. What a pain this was.

Comment on lines +106 to +107
--arrow-height: 0.375rem;
--arrow-width: 0.625rem;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason not to duplicate these values in two spots or did you find value in bringing these up the chain to variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I originally used them in quite a few more places. But the only places they're used now are co-located. So I'll go ahead and duplicate them instead.

data-test="arrow"
${ref(this.#arrowElementRef)}
>
${choose(this.effectivePlacement, [
Copy link
Collaborator

Choose a reason for hiding this comment

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

fancy!

src/tooltip.ts Outdated
}

#hide() {
this.#cleanUpFloatingUi?.();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no one else has any ideas, I can pull this branch down tomorrow AM and give it a look

@clintcs
Copy link
Collaborator Author

clintcs commented Aug 15, 2024

I noticed one small bug with the private-label stuff I think:

Awesome find! Looking into it now.

import { createRef, ref } from 'lit/directives/ref.js';
import { customElement, property, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { offsetParent } from 'composed-offset-position';
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to remove the composed-offset-position dependency from package.json now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do. Nice catch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@danwenzel danwenzel left a comment

Choose a reason for hiding this comment

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

🎉

Copy link
Collaborator Author

@clintcs clintcs Aug 15, 2024

Choose a reason for hiding this comment

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

I noticed one small bug with the private-label stuff I think:

@ynotdraw: Easy enough to fix. But this test should have caught it.

It didn't because I didn't add a await aTimeout(0) to it to await Floating UI—to give Tooltip a chance to become visible. And, of course, aTimeout doesn't work when timers are fake.

So I had work the timer stuff. I noticed a couple other tests were falsely passing and reworked those too. Instead of using fake timers, I gave the tests a way to override Tooltip's open and close delays.

I don't love the solution but couldn't find better way. More on why I went with data attributes here. Let me know what you think, all considered, or if you have other ideas.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, also swapped out ARIA attribute selectors for data attribute selectors after coming across this, which I think I added.

Perhaps an example of why we should always use data attribute selectors in tests despite ARIA attribute selectors being in vogue because of Testing Library.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice work going through all of that! What you have here makes sense to me 👍

Perhaps an example of why we should always use data attribute selectors in tests despite ARIA attribute selectors being in vogue because of Testing Library.

Definitely. If I've got some time tomorrow I can write some thoughts up for CONTRIBUTING.md and update any remaining stragglers in the codebase if we'd like.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice. I've got a note too. I'll get to it if you don't.

Copy link
Collaborator

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

🎉 popover is so amazing!

Comment on lines +256 to +262
// The open and close delays are stored in data attributes so tests can
// configure them. Tests configure them, rather than using fake timers,
// because they need real timers so they can await Floating UI's setup.
//
// Conditionals here and in `#scheduleClose` based on `navigator.webdriver`
// would be a lot nicer. But the non-`navigator.webdriver` condition would
// never get hit in tests, so we'd fail to meet our coverage thresholds.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The other nice thing about these is that they're still private to the component due to the closed shadow root, so consumers have no way to adjust them (other than going through design and talking to us!). You love to see it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, yeah. CSS variables would work here too. But, of course, they have the drawback of being public.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice work going through all of that! What you have here makes sense to me 👍

Perhaps an example of why we should always use data attribute selectors in tests despite ARIA attribute selectors being in vogue because of Testing Library.

Definitely. If I've got some time tomorrow I can write some thoughts up for CONTRIBUTING.md and update any remaining stragglers in the codebase if we'd like.

@clintcs
Copy link
Collaborator Author

clintcs commented Aug 15, 2024

🎉 popover is so amazing!

No kidding. Many problems would be unfixable without it. I'm just going to throw popover on everything from now on. Not going to think twice.

@clintcs clintcs merged commit bb18490 into main Aug 15, 2024
@clintcs clintcs deleted the switch-tooltip-to-popover branch August 15, 2024 22:47
@github-actions github-actions bot mentioned this pull request Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载