-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use BoundsObserver to keep tooltip over the wrapper #18782
Conversation
...to prevent UI junks.
@yuwenmemon @0xmiroslav One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
@flodnv @parasharrajat @0xmiroslav @yuwenmemon As the template says...
...I linked both issues my PR solves by my intention. But I might've confused some bots, so maybe it wasn't a good idea? |
This is fine. I will be reviewing this PR @0xmiroslav |
@cubuspl42 if this PR solves #15757 as well, that's great. But won't this conflict with #16052 which put #15757 on hold? |
It does conflict, although not very seriously. I tested a variant of this branch that's rebased on top of #16052. @parasharrajat When do you think we could expect #16052 to be merged? |
Probably tomorrow. |
...which could occur when scrolling down.
I think it's ok if it conflicts, no...? |
|
||
// We may need this check due to the reason that the animation start will fire async | ||
// and hideTooltip could fire before it thus keeping the Tooltip visible | ||
if (this.shouldStartShowAnimation) { |
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.
Continuing this thread.
Please note that this check is nearly directly below the this.shouldStartShowAnimation = true
assignment. The only barrier between is the awaiting for this.getWrapperPositionPromise.promise
. That promise is gone, so the shouldStartShowAnimation
flag doesn't have any use anymore, as I see it.
@parasharrajat I think we're ready for your next round! |
We are running a discussion internally as it seems the lib is overengineered. Do we really need https://github.com/html-ng/bounding-client-rect-observer/blob/04a7cbbafe6a3fbafe93cbf4be2bf6e79165757c/src/handle.ts#L8? |
@parasharrajat I'd be happy to take part in that discussion if you find this appropriate.
Let me know which parts you would remove or implement differently.
Probably not, it's just a util. It could be inlined, it's a matter of opinion whether that would be less or more readable code. It's analogical to things like Is the presence of |
There is no flaw as such. |
@parasharrajat Let me know when we can take a next step with this PR. What's the state of the internal discussion? What are the blockers for merging this PR? What do you think about starting the PR reviewer's checklist? I think it could be done independently from the internal discussion. |
@cubuspl42 I will review this asap. |
Thank you. |
This PR is still held on the internal discussion. Sorry for the delay here. We will get back with an update as soon as possible. |
This is back in motion. |
Yes, please proceed 👍 |
@parasharrajat @flodnv Thanks for the update! From my perspective, the PR has been essentially ready since the beginning, so I'm waiting for your turn guys 🙃 |
src/styles/getTooltipStyles.js
Outdated
targetWrapperWidth, | ||
targetWrapperHeight, | ||
maxWidth, | ||
tooltipWidth, | ||
tooltipHeight, | ||
tooltipContentWidth, | ||
wrapperMeasuredWidth, | ||
wrapperMeasuredHeight, | ||
contentMeasuredWidth, |
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.
These are confusing. They were making more sense earlier.
component means the toolip target. It can be changed to target. That is fine.
but wrapperMeasuredWidth is confusing. Earlier name tooltipWidth
ws correct as it is width of tooltip itself. Now it is confusing to see two wrapper names.
I would say you revert
wrapperMeasuredWidth,
wrapperMeasuredHeight,
contentMeasuredWidth,
back to old names.
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.
I aimed at consistency. Maybe then I'll change targetWrapperWidth/Height
to targetWidth/Height
?
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.
And wrapper
to tooltip
?
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.
yeah, you can do this. Let's not increase the scope of the PR.
Actually, I don't approve extra unrelated changes to any PR. Even though these are good refactors but completely unnecessary.
As you have already applied these, let's not remove them.
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.
I pushed a second suggestion. I tried to take your perspective into consideration, while also trying to stay consistent.
}, []); | ||
|
||
const {animationStyle, tooltipWrapperStyle, tooltipTextStyle, pointerWrapperStyle, pointerStyle} = useMemo( | ||
const {animationStyle, wrapperStyle, textStyle, pointerWrapperStyle, pointerStyle} = useMemo( |
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 named wrapperStyle
to tooltipwrapperStyle
to distinguish it from pointerWrapperStyle
. IMO, that was fine too.
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.
But the reference is named wrapper
🙁 I renamed wrapper
to rootWrapper
and wrapperStyle
to rootWrapperStyle
, trying to address both concerns
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.
Reviewer Checklist
- I have verified the author checklist is complete (all boxes are checked off).
- I verified the correct issue is linked in the
### Fixed Issues
section above - I verified testing steps are clear and they cover the changes made in this PR
- I verified the steps for local testing are in the
Tests
section - I verified the steps for Staging and/or Production testing are in the
QA steps
section - I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
- I verified the steps for local testing are in the
- I checked that screenshots or videos are included for tests on all platforms
- I included screenshots or videos for tests on all platforms
- I verified tests pass on all platforms & I tested again on:
- Android / native
- Android / Chrome
- iOS / native
- iOS / Safari
- MacOS / Chrome / Safari
- MacOS / Desktop
- If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- I verified proper code patterns were followed (see Reviewing the code)
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
toggleReport
and notonIconClick
). - I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g.
myBool && <MyComponent />
. - I verified that comments were added to code that is not self explanatory
- I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
- I verified any copy / text shown in the product is localized by adding it to
src/languages/*
files and using the translation method - I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the
Waiting for Copy
label for a copy review on the original GH to get the correct copy. - I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
- I verified the JSDocs style guidelines (in
STYLE.md
) were followed
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
- If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- I verified that this PR follows the guidelines as stated in the Review Guidelines
- I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar
, I verified the components usingAvatar
have been tested & I retested again) - I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
- If a new component is created I verified that:
- A similar component doesn't exist in the codebase
- All props are defined accurately and each prop has a
/** comment above it */
- The file is named correctly
- The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- The only data being stored in the state is data necessary for rendering and nothing else
- For Class Components, any internal methods passed to components event handlers are bound to
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor) - Any internal methods bound to
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
) - All JSX used for rendering exists in the render method
- The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- If any new file was added I verified that:
- The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
- If a new CSS style is added I verified that:
- A similar style doesn't already exist
- The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)
- If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
- If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avatar
is modified, I verified thatAvatar
is working as expected in all cases) - If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
- If a new page is added, I verified it's using the
ScrollView
component to make it scrollable when more elements are added to the page. - If the
main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
cc: @flodnv
🎀 👀 🎀 C+ reviewed
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.
Nice PR, thanks!
import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; | ||
|
||
// A "target" for the tooltip, i.e. an element that, when hovered over, triggers the tooltip to appear. The tooltip will |
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.
This comment confuses me a bit. Is it meant to describe what class Tooltip
is? If so, I am confused that class Tooltip
is the target for the tooltip 😕
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.
No, it is defining the term Target in the tooltip context.
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.
Ok so why is this comment here? It feels out of context, no?
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.
Actually, the target term is used a lot of places in the tooltip context across multiple components and files so there wasn't any good place to put it. Do you have something in mind? We can move it there.
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.
Can we put it where we define the target for example?
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.
I personally agree that the comment is a bit confusing and that the name is fine. For all intents and purposes it is a... tooltip. The "target" feels like it would refer to the wrapped element. If this comment is attempting to explain how the tooltip works at a high level it could probably be better.
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.
This comment is only defining the term target
in reference to the code in the Tooltip component so that it is clear what are we referring to when we encounter variables like targetWidth
targetHeight
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.
Ok so how about this for a better comment:
We use this Tooltip component to wrap an element on which we want to show a tooltip. The "target" for the tooltip is the wrapped element which when hovered over, triggers the tooltip to appear.
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.
@flodnv You're right, this is much better and what I actually had in mind. I'll create a follow-up PR tomorrow.
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.
Let's get this merged in the next 30 mins which will be under 3 days ❤️ |
Congrats, that’s your 5th PR merged! 🎉 Do you know about the ContributorPlus role? It’s an opportunity to earn more in the Expensify Open Source community. Keep up the great work - thanks! |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Thank you for merging this. Please let me know if you want me to move the comment somewhere else. I can spin a PR for that. |
🚀 Deployed to staging by https://github.com/flodnv in version: 1.3.17-0 🚀
|
🚀 Deployed to production by https://github.com/chiragsalian in version: 1.3.17-5 🚀
|
This issue was created by the change introduced in this PR. The issue is: "tooltip appears at top left corner on pressing back icon" Steps to reproduce:
|
Details
Use
BoundsObserver
to keep tooltip over the wrapperFixed Issues
$ #15229
$ #15757
PROPOSAL: #15229 (comment)
Tests
Offline tests
QA Steps
See Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
tooltip-avatar.mp4
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android