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

fix(Tooltip): remove click stopPropagation #9959

Merged
merged 2 commits into from
Nov 4, 2021

Conversation

FrivalszkyP
Copy link
Contributor

Closes #9958

Changelog

Removed

  • Remove e.stopPropagation() from the click event handler. In React 17, the stopPropagation prevents other Tooltip's clickoutside handlers from executing. It probably affects other clickoutside event handlers from executing.

Please note: removing it might cause other side effects but I couldn't come up with any scenarios like that.

Testing / Reviewing

See steps to repro in this Issue: #9958

@FrivalszkyP FrivalszkyP requested a review from a team as a code owner October 27, 2021 12:28
@netlify
Copy link

netlify bot commented Oct 27, 2021

✔️ Deploy Preview for carbon-react-next ready!

🔨 Explore the source changes: 21adaf1

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-react-next/deploys/61831bf3ef8f93000847986b

😎 Browse the preview: https://deploy-preview-9959--carbon-react-next.netlify.app

@netlify
Copy link

netlify bot commented Oct 27, 2021

✔️ Deploy Preview for carbon-elements ready!

🔨 Explore the source changes: 21adaf1

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-elements/deploys/61831bf33229c100084de4d5

😎 Browse the preview: https://deploy-preview-9959--carbon-elements.netlify.app

@netlify
Copy link

netlify bot commented Oct 27, 2021

✔️ Deploy Preview for carbon-components-react ready!
Built without sensitive environment variables

🔨 Explore the source changes: 21adaf1

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-components-react/deploys/61831bf3777a94000711147c

😎 Browse the preview: https://deploy-preview-9959--carbon-components-react.netlify.app

@tay1orjones
Copy link
Member

tay1orjones commented Nov 2, 2021

Hey @FrivalszkyP! Thanks for submitting this change. Good catch here - the changes to event pooling in React v17 are probably the culprit.

The stopPropagation was added quite a while ago. The example used in the commit message d32424c says it's for tooltips inside buttons.

I'll do some quick tests on this to see if I can find any side effects with tooltips in modals or tooltips.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

I couldn't find any side effects 👍

@FrivalszkyP
Copy link
Contributor Author

@tay1orjones, thanks for being so thorough, I really appreciate it!

@FrivalszkyP
Copy link
Contributor Author

@tay1orjones I tested it and the Tooltip inside a Button issue could definitely be a problem if we merge this PR. On the other hand, a Tooltip inside a Button is just a button inside another button, in terms of the AOM, so it should be avoided anyway. So the original reason the stopPropagation() was added would have been better handled by refactoring the design and not adding the Tooltip inside a Button.

@tay1orjones
Copy link
Member

@FrivalszkyP Yes I agree, tooltips shouldn't be placed inside buttons. We do use a tooltip for the hasIconOnly variant, but when clicking/dismissing the tooltip the same behavior is seen between the deploy preview storybook here and the production storybook.

tooltips.dismiss.and.focus.to.button.mov

@FrivalszkyP
Copy link
Contributor Author

@tay1orjones interestingly, it works differently for me. Chrome 95 on MacOS Big Sur 11.6. Using the deploy preview, clicking on the tooltip bubble does not close the bubble for me. I'll take a closer look on this, also I'll add storybook actions for the button onclick event and see whether the event fires on my branch. Thanks for bringing this to my attention!

@ZachStowellIBM
Copy link
Contributor

@FrivalszkyP @tay1orjones - I'm actually running into an issue due to these changes.

We have a DataTable, that has sortable headers. One of these headers has a tooltip in it.
Screen Shot 2021-12-14 at 4 49 14 PM
Screen Shot 2021-12-14 at 4 49 29 PM

The issue we run in to is the exact scenario you were discussing above, about tooltips inside of buttons (since the ability to toggle the sort order is effectively a button).

What's the best course of action here from a Carbon perspective? This seems like a use case where we would want to stopPropagation, however there's no mechanism in the Tooltip component to do so.

@tay1orjones
Copy link
Member

@ZachStowellIBM Unfortunately, interactive controls can't have focusable descendants like this. Nested interactive controls are not announced by screen readers. Because of this, placing a Tooltip inside a parent element that is interactive will fail WCAG Success Criterion 4.1.2.

Until this PR, the Tooltip masked this problem for quite some time by calling stopPropagation internally. It's been there all along though. The event propagation can be stopped in an onClick on an element wrapping the Tooltip, but I'd caution that as a temporary workaround.

Rel: #10284

@ZachStowellIBM
Copy link
Contributor

Thanks for the info @tay1orjones! We'll be sure to make changes on our end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: [React] Tooltip handleClickOutside is buggy with React 17 and two Tooltips
4 participants