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 has wrong position if it has a parent with absolute position and moved transform #29

Closed
DanielSidhion opened this issue Dec 17, 2023 · 5 comments
Labels
Type: Bug Something isn't working

Comments

@DanielSidhion
Copy link

If the tooltip is added to an element that has a parent with absolute position + moved transform, it gets positioned in the wrong place.

Reproduction: https://svelte.dev/repl/0468e8f7712f4b4fbf33a14ff1be2f0e?version=4.2.8

Reading the code (#27) that fixed the initial issue (#25), it looks like if an offsetParent has absolute positioning, it would be easier to just position the tooltip assuming the parent's bounding client rect is the (0, 0) origin, and ignore any previous offsetParents that may exist in the tree. Basically, the code shouldn't expect left and top to determine the actual positioning of the element, but should still get the correct bounding rect using .getBoundingClientRect().

More context: I'm using Svelte Flow, and they define nodes with position: absolute, but move the nodes using transform: translate(...) instead of setting left and top.

@dysfunc
Copy link
Contributor

dysfunc commented Dec 18, 2023

#30 addresses this issue and fixes a bug introduced in the last change

@dysfunc dysfunc closed this as completed Dec 18, 2023
@philmas
Copy link

philmas commented Dec 29, 2023

It seems there is a bug, but perhaps can be addressed in a different manner. When I have a parent div relative of which a child having the tooltip prop and class absolute the tooltip works fine until the page is scrolled which messes up the position of the tooltip. Any thoughts on this?

@dysfunc
Copy link
Contributor

dysfunc commented Dec 29, 2023

Can you create a REPL with the issue?

@DanielSidhion
Copy link
Author

@philmas My apologies, but I didn't understand well the scenario you mentioned. I tried creating a repro here with a few variations, and while I think those may have shown more bugs in the code, the behaviour was the same regardless of whether the page was scrolled or not.

@philmas
Copy link

philmas commented Dec 29, 2023

Apologies, it is quite stupid to not show the example. I wrote down something quickly:

<script lang="ts">
	let name = 'world';
</script>

<div style="display:grid;">
	{#each Array(6) as _, i}
    <label style="position:relative; display:flex; background-color:#ccc;">
			<input
								type="radio"
				name="radio-input"
							/>
			<div>
				Some item
			</div>
			<div
								class="text-xs text-gray-500 bg-gray-100 h-8 w-8 hover:bg-gray-200 p-1 rounded-full absolute top-4 right-4"
								use:tooltip={{
									content: `<b>Description</b><p>No description available</p>`,
									position: 'top',
									animation: 'slide',
									arrow: true
								}}
							>
								<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
									<path
										fill="currentColor"
										d="M11 7v2h2V7zm3 10v-2h-1v-4h-3v2h1v2h-1v2zm8-5c0 5.5-4.5 10-10 10S2 17.5 2 12S6.5 2 12 2s10 4.5 10 10m-2 0c0-4.42-3.58-8-8-8s-8 3.58-8 8s3.58 8 8 8s8-3.58 8-8"
									/></svg
								>
							</div>
		</label>
{/each}
</div>

Otherwise, I will come back to you when I have more time on my hands because I am not as handy with REPLs. This is basically the situation. I was able to omit the issue by not using relative/absolute :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants