-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[PositionedOverlay][Tooltip] Fix tooltip scroll bug #7899
Conversation
c49543f
to
deb41ab
Compare
size-limit report 📦
|
b347a57
to
43c616c
Compare
/snapit |
43c616c
to
52c7534
Compare
🫰✨ Thanks @jeradg! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/plugin-polaris@0.0.0-snapshot-release-20221216203819 yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20221216203819 yarn add @shopify/polaris@0.0.0-snapshot-release-20221216203819 yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20221216203819 |
}), | ||
() => { | ||
if (this.overlay == null || this.scrollableContainer == null) { | ||
if (this.overlay == null || this.firstScrollableContainer == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're registering scroll events for all scrollable containers but this measurement is only ever using the first one as a reference. Would that result in the correct positioning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it results in the correct positioning.
In main
(i.e., without the bugfix) the tooltip is always positioned correctly when first rendered, regardless of what container the trigger activator is in. The bug isn't with the calculation of the position, it's that we're not triggering this calculation for all relevant scroll events.
With this fix, we still want to use the first scrollable container to determine the position of the tooltip, because that's the container the trigger activator element is within (and the tooltip is visually positioned relative to its trigger activator).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup looks like it's working. The scroll container dimensions are only used for adjusting the tooltip position (above, below, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top hat and changes look good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code + 🎩 looks good to me, I like the little bounce on the tooltip when main page scrolls ahah oddly nice. Good work!!
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @shopify/polaris@10.18.0 ### Minor Changes - [#7992](#7992) [`e8f74f4cd`](e8f74f4) Thanks [@aveline](https://github.com/aveline)! - Added support for `outline` to `Box` ### Patch Changes - [#7988](#7988) [`382784f4e`](382784f) Thanks [@kyledurand](https://github.com/kyledurand)! - Reduced spacing on ChoiceList children - [#7899](#7899) [`930f077eb`](930f077) Thanks [@jeradg](https://github.com/jeradg)! - Fixed a bug where Tooltips nested in Scrollable containers sometimes don't update their positions correctly - [#7831](#7831) [`47487ee0c`](47487ee) Thanks [@acmertz](https://github.com/acmertz)! - Updated the focus helper functions to no longer treat buttons with `aria-disabled="true"` and `tabindex="-1" (but no`disabled\` attribute) as focusable. ## @shopify/plugin-polaris@0.0.25 ## polaris.shopify.com@0.28.2 ### Patch Changes - Updated dependencies \[[`382784f4e`](382784f), [`930f077eb`](930f077), [`47487ee0c`](47487ee), [`e8f74f4cd`](e8f74f4)]: - @shopify/polaris@10.18.0 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Closes https://github.com/Shopify/core-workflows/issues/663 This PR fixes a bug with `Tooltip` and other consumers of `PositionedOverlay` where the position of the overlay does not correctly update when the overlay's closest `Scrollable` ancestor is **_not_** being scrolled, but some more distant ancestor node **_is_** being scrolled. In such cases, the overlay position moves with the more distant ancestor node rather than the correct `Scrollable` node. (The bug specifically occurs `Tooltip` instances rendered in a `Scrollable`, because the `PositionedOverlay` from the tooltip is rendered in a `PortalContainer`, which is a descendant of the `body` rather than the tooltip's `Scrollable`.) ### WHAT is this pull request doing? <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> This PR ensures that `scroll` event handlers are added to all scrollable ancestors of the component, rather than just the nearest scrollable ancestor. This fixes a bug where the tooltip "sticks" to the page body rather than the correct scrollable container. This video shows the correct behaviour: https://user-images.githubusercontent.com/1948799/210642458-ec0f7a77-9021-46c9-8283-8e7665a05ade.mov ### How to 🎩 Tophatting URL: https://admin.web.tooltip-polaris.jerad-gallinger.us.spin.dev/store/shop1 - Open the admin - Resize your browser window to be tall enough for the left nav to not scroll - In the left-hand nav, hover over `Online Store`. The tooltip should appear as usual. - While still hovering over the nav item, scroll the page (with up/down arrow keys, trackpad gestures, or scroll wheel). When the main page content scrolls, the tooltip should reposition so that it still appears above the nav item (rather than scrolling with the main page content). - Resize the height of the browser so that the left nav content overflows the height of the nav and becomes scrollable. - Scroll the left nav to the bottom of its contents. Hover over the `Online Store` item so the tooltip appears. - While still hovering over the nav item, scroll the page down (with up/down arrow keys, trackpad gestures, or scroll wheel). When the main page content scrolls, the tooltip should reposition so that it still appears above the nav item (rather than scrolling with the main page content). ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [X] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @shopify/polaris@10.18.0 ### Minor Changes - [Shopify#7992](Shopify#7992) [`e8f74f4cd`](Shopify@e8f74f4) Thanks [@aveline](https://github.com/aveline)! - Added support for `outline` to `Box` ### Patch Changes - [Shopify#7988](Shopify#7988) [`382784f4e`](Shopify@382784f) Thanks [@kyledurand](https://github.com/kyledurand)! - Reduced spacing on ChoiceList children - [Shopify#7899](Shopify#7899) [`930f077eb`](Shopify@930f077) Thanks [@jeradg](https://github.com/jeradg)! - Fixed a bug where Tooltips nested in Scrollable containers sometimes don't update their positions correctly - [Shopify#7831](Shopify#7831) [`47487ee0c`](Shopify@47487ee) Thanks [@acmertz](https://github.com/acmertz)! - Updated the focus helper functions to no longer treat buttons with `aria-disabled="true"` and `tabindex="-1" (but no`disabled\` attribute) as focusable. ## @shopify/plugin-polaris@0.0.25 ## polaris.shopify.com@0.28.2 ### Patch Changes - Updated dependencies \[[`382784f4e`](Shopify@382784f), [`930f077eb`](Shopify@930f077), [`47487ee0c`](Shopify@47487ee), [`e8f74f4cd`](Shopify@e8f74f4)]: - @shopify/polaris@10.18.0 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
WHY are these changes introduced?
Closes https://github.com/Shopify/core-workflows/issues/663
This PR fixes a bug with
Tooltip
and other consumers ofPositionedOverlay
where the position of the overlay does not correctly update when the overlay's closestScrollable
ancestor is not being scrolled, but some more distant ancestor node is being scrolled. In such cases, the overlay position moves with the more distant ancestor node rather than the correctScrollable
node.(The bug specifically occurs
Tooltip
instances rendered in aScrollable
, because thePositionedOverlay
from the tooltip is rendered in aPortalContainer
, which is a descendant of thebody
rather than the tooltip'sScrollable
.)WHAT is this pull request doing?
This PR ensures that
scroll
event handlers are added to all scrollable ancestors of the component, rather than just the nearest scrollable ancestor. This fixes a bug where the tooltip "sticks" to the page body rather than the correct scrollable container.This video shows the correct behaviour:
tooltip-bugfix.mov
How to 🎩
Tophatting URL: https://admin.web.tooltip-polaris.jerad-gallinger.us.spin.dev/store/shop1
Online Store
. The tooltip should appear as usual.Online Store
item so the tooltip appears.🎩 checklist
README.md
with documentation changes