Skip to content

Commit cfd632a

Browse files
committed
Floating: to keep position of the floating box, target element should use "visibility: hidden" instead of "display:none".
1 parent e4abcb4 commit cfd632a

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/components/Preview.vue

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,26 @@ const render = (text: string) => $md.render(text);
3535
<div class="flex">
3636
<div class="virtual-dom">
3737
Virtual DOM
38-
<Floating placement="top-start" max-width="200px" class="large-font" theme="warning"">
39-
<template #default>
40-
<button>
41-
Button with floating tooltip
42-
</button>
43-
</template>
44-
<template #content>
45-
My Long Long Long Long Long Long Long Long Long Long Tooltip
46-
</template>
47-
</Floating>
38+
<span class="hover-anchor">
39+
<span class="hover-box">
40+
<Floating
41+
placement="top-start"
42+
:max-width="500"
43+
class="large-font"
44+
theme="warning"
45+
:delay="200"
46+
>
47+
<template #default>
48+
<button>
49+
?
50+
</button>
51+
</template>
52+
<template #content>
53+
Virtual DOM is a programming concept where an ideal, or "virtual", representation of a UI is kept in memory and synced with the "real" DOM by a library such as React. This process is called reconciliation.
54+
</template>
55+
</Floating>
56+
</span>
57+
</span>
4858
<MarkdownRenderer class="preview" :content="render(content)" />
4959
</div>
5060
<div class="inner-html">
@@ -89,13 +99,30 @@ code {
8999
}
90100
91101
.large-font {
92-
font-size: 2em;
102+
font-size: 1.5em;
103+
}
104+
105+
.hover-anchor {
106+
position: relative;
107+
visibility: hidden;
108+
div:hover:has(> .hover-anchor) & {
109+
visibility: visible;
110+
}
111+
}
112+
.hover-box {
113+
position: absolute;
114+
top: -0.8em;
115+
left: 0.3em;
93116
}
94117
95118
.floating-wrapper[data-theme~="warning"] {
96119
background-color: yellow;
97120
color: red;
98121
border-color: red;
122+
.floating-arrow {
123+
background-color: yellow;
124+
border-color: red;
125+
}
99126
}
100127
101128
</style>

0 commit comments

Comments
 (0)