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

Tooltip: Add new hideOnClick prop #54406

Merged
merged 2 commits into from Sep 13, 2023
Merged

Tooltip: Add new hideOnClick prop #54406

merged 2 commits into from Sep 13, 2023

Conversation

brookewp
Copy link
Contributor

What?

While looking into replacing the ui/tooltip component, I came across a feature that isn't currently possible with our Tooltip component, due to legacy behavior where the tooltip is hidden on anchor click. This implementation of ui/tooltip can be found in ColorPicker and the feature by using the copy button:

Screen Recording 2023-09-12 at 5 51 30 PM

Why?

To make a more dynamic tooltip possible, like in the case of ColorPicker's copy button:

{ copiedColor === color.toHex()
? __( 'Copied!' )
: __( 'Copy' ) }

How?

To avoid a regression, an optional prop of hideOnClick with a default of true has been added. By default, it will behave the same as it does now, but there will be an option to hide the tooltip when the anchor. This will allow for possibilities like the abovementioned example.

A test has been added to test the false case to ensure the behavior is as expected.

Testing Instructions

  1. Ensure tests pass npm run test:unit packages/components/src/tooltip/test/index.tsx
  2. npm run storybook:dev
  3. See new prop and type
  4. Toggle option and ensure tooltip is hidden on anchor click when hideOnClick is set to true and stays visible when false

@brookewp brookewp added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Sep 13, 2023
@brookewp brookewp added this to In progress (owned) ⏳ in WordPress Components via automation Sep 13, 2023
@brookewp brookewp self-assigned this Sep 13, 2023
@github-actions
Copy link

Flaky tests detected in 7b75dc9905d657f8b83030257c1b7bbbdeef565c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6166668891
📝 Reported issues:

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Looks good to me! And thank you for adding unit tests 🚀

Let's add a CHANGELOG entry before merging.

@@ -310,4 +310,26 @@ describe( 'Tooltip', () => {
await screen.findByRole( 'button', { description: 'tooltip text' } )
).toBeInTheDocument();
} );

it( 'should not hide tooltip when the anchor is clicked if hideOnClick is false', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Might be useful to have a test to confirm that if hideOnClick is true or not specified, the tooltip still gets hidden on anchor click.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have a test that is kind-of implicitly testing for that

it( 'should not show tooltip on focus as result of mouse click', async () => {
const user = userEvent.setup();
render( <Tooltip { ...props } /> );
await user.click( screen.getByRole( 'button', { name: /Button/i } ) );
expect(
screen.queryByRole( 'tooltip', { name: /tooltip text/i } )
).not.toBeInTheDocument();
await cleanupTooltip( user );
} );

Although I'd understand if you preferred having a more explicit check.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we can also expand the test description if we want, but yeah, that test does the job IMHO 👍

@brookewp brookewp marked this pull request as ready for review September 13, 2023 15:48
@brookewp brookewp merged commit db0ec5c into trunk Sep 13, 2023
50 checks passed
WordPress Components automation moved this from In progress (owned) ⏳ to Done 🎉 Sep 13, 2023
@brookewp brookewp deleted the tooltip/add-hideonclick branch September 13, 2023 18:50
@github-actions github-actions bot added this to the Gutenberg 16.7 milestone Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants