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

#2450 - Anchor tooltip to the element in 'Group Activity' area #2482

Merged
merged 6 commits into from
Dec 29, 2024

Conversation

SebinSong
Copy link
Collaborator

@SebinSong SebinSong commented Dec 26, 2024

closes #2450

[Before fix]

tooltip-prev-fix.mp4

[After fix]

tooltip-after-fix.mp4

(cc. @taoeffect )
There are two issues pointed out in the issue which are,

1] Tooltip should be anchored to the app (rather than user's screen).
2] Tooltip should be closable.

Firstly, (As you can see in the video attached above too) I noticed 1. is not a mobile-specific issue but does happen in desktop too. Apparently, this behaviour was intentionally implemented by the component author as you can read in below comment too:

directives: {
// The tooltip instead of being rendered on the original DOM position
// it's appended to the DOM, away from every other elements
// so no element CSS can influence tooltip styles (position, size)
appendToBody: {

The logic to determine tooltip position written as part of this custom-directive is currently widely used across the app. So as a fix for the issue, I added a component prop(anchorToElement) that allows to opt out of this behaviour and attach the tooltip to the trigger element instead.

@dotmacro Regarding 2. you pointed out, the tooltip does look unable to close on mobile-browser but it actually remains there because the trigger element stays focused once we tap on it on mobile. We can just unfocus it to make it disappear (it means not only clicking on other call-to-actions in the page but also merely clicking on a random position in the background too), which I think is right behaviour. So I haven't made any changes regarding 2.. Hope it sounds good.

Thanks,

@SebinSong SebinSong self-assigned this Dec 26, 2024
Copy link

cypress bot commented Dec 26, 2024

group-income    Run #3618

Run Properties:  status check passed Passed #3618  •  git commit 8977ce1827 ℹ️: Merge 137eb532badab2471e6c39cc6dd4dfa20153d2e0 into b6dc54d0a00fc21026dccb61651e...
Project group-income
Branch Review sebin/task/#2450-anchored-closable-tooltip
Run status status check passed Passed #3618
Run duration 10m 25s
Commit git commit 8977ce1827 ℹ️: Merge 137eb532badab2471e6c39cc6dd4dfa20153d2e0 into b6dc54d0a00fc21026dccb61651e...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 112
View all changes introduced in this branch ↗︎

@SebinSong SebinSong changed the title [WIP] #2450 Anchor tooltip to the element in 'Group Activity' area #2450 - Anchor tooltip to the element in 'Group Activity' area Dec 26, 2024
}
if (!this.manual) { return false }
// Manually toggle on/off the tooltip (reference: ProfileCard.vue)
if (this.deactivated || !this.manual) { return }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simplifying the existing logic here.

@@ -67,6 +81,13 @@ export default ({
type: String,
required: false,
default: ''
},
anchorToElement: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A prop to anchor the tooltip to the trigger element instead. Let me know if there is a suggestion for a better name.

const { scrollX, scrollY } = window
const { width, height, left, top } = this.trigger
const windowHeight = window.innerHeight
const spacing = 16
let x, y
let transform
let absPosition // For css top/left/bottom/right properties to use along with 'position: absolute'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the case of anchoring the tooltip to a certain element (which is a trigger element in our case), Things are easier if css transform: translate(...) is used along with absolute positioning (specifying top, left, right, bottom properties). So added this variable here.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Excellent work @SebinSong!

@dotmacro
Copy link
Member

the tooltip does look unable to close on mobile-browser but it actually remains there because the trigger element stays focused once we tap on it on mobile. We can just unfocus it to make it disappear (it means not only clicking on other call-to-actions in the page but also merely clicking on a random position in the background too), which I think is right behaviour.

In my testing, on iOS there is no way for a mobile user to close this tooltip except by opening a different tooltip. Tapping on the background has no effect. I double-checked, and this still seems to be the case on testing. I have not tested on this PR, as you say you made no relevant changes. Let me know what other info you need to help troubleshoot :)

@SebinSong
Copy link
Collaborator Author

@dotmacro

on iOS there is no way for a mobile user to close this tooltip except by opening a different tooltip.

I don't see this happening on my Android browsers and PWA, so I guess that is an iOS specific issue.

@SebinSong
Copy link
Collaborator Author

SebinSong commented Dec 27, 2024

@taoeffect Apart from the iPhone-specific issue mentioned above, I think this PR is ready. (I use Android device and cannot reproduce that issue on my machine)

@taoeffect taoeffect merged commit 160bb62 into master Dec 29, 2024
4 checks passed
@taoeffect taoeffect deleted the sebin/task/#2450-anchored-closable-tooltip branch December 29, 2024 03:28
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.

Tooltips on mobile should be anchored & closable
3 participants