Skip to content

USWDS - Tooltip: Add opacity:0 to initial state#5475

Merged
thisisdano merged 2 commits into
developfrom
al-tooltip-opacity-0
Sep 28, 2023
Merged

USWDS - Tooltip: Add opacity:0 to initial state#5475
thisisdano merged 2 commits into
developfrom
al-tooltip-opacity-0

Conversation

@amyleadem

@amyleadem amyleadem commented Aug 29, 2023

Copy link
Copy Markdown
Contributor

Summary

Restored the opacity: 0 style rule to the tooltip body's initial state. This prevents the component from flickering if its position needs to be recalculated.

Breaking change

This is not a breaking change.

Related issue

Closes #4458

Related pull requests

Changelog PR

Preview link

Tooltip component

Problem statement

To prevent flickering in the tooltip component, the tooltip is programmed to receive an opacity shift slightly after the tooltip positioning is set. This comment explains that the initial state should be set to opacity: 0 so that any position changes will occur when the component is visibly hidden.

However, the tooltip does not receive an initial style of 0 opacity, which can result in flickering.

It looks like this CSS declaration used to exist, but was possibly removed by mistake when refactoring how the tooltip positioning works (see the code changes in this PR).

Solution

Reinstating the initial opacity: 0 style rule should allow the is-visible class to perform as expected and prevent flickering in the tooltip.

Testing and review

  • Open the tooltip component and confirm that the tooltip toggles visibility as expected.
  • Confirm that toggling the is-visible class in web inspector shows and hides the component as expected.

@mahoneycm mahoneycm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code is working great!

I had to add the class is-set in addition to is-visible while testing the class additions, but hover toggling worked as expected!

@mejiaj mejiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just a minor note on documenting why we need the style rule.

Comment thread packages/usa-tooltip/src/styles/_usa-tooltip.scss Outdated
Co-authored-by: James Mejia <james.mejia@gsa.gov>

@thisisdano thisisdano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Simple and effective!

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.

USWDS - Bug: Tooltip opacity is not set to 0

4 participants