Skip to content

Commit bcfc7f5

Browse files
committed
Basic handling of tooltip bottom positioning
1 parent 0f02e1b commit bcfc7f5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/editor/src/plugins/toolbar/Tooltip.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const useRect = (key, ...args) => {
1717
try {
1818
const el = findDOMNode(key)
1919
const rect = el.getBoundingClientRect()
20+
rect.clientHeight = document.documentElement.clientHeight
21+
rect.scrollY = window.scrollY
22+
rect.maxHeight = rect.clientHeight + rect.scrollY
2023
// todo: find cursor left?
2124
setRect(rect)
2225
} catch (e) {}
@@ -94,11 +97,21 @@ export default props => {
9497
// (temporary) only render for images and links
9598
if (!forms.length) return false
9699

100+
let top = rect.bottom
101+
let bottom
102+
103+
// todo: get Card height
104+
if (rect.bottom + rect.height + 128 > rect.maxHeight) {
105+
top = null
106+
bottom = 32
107+
}
108+
97109
return createPortal(
98110
<Card
99111
style={{
100112
position: 'fixed',
101-
top: rect.bottom,
113+
top,
114+
bottom,
102115
left: rect.left
103116
}}
104117
>

0 commit comments

Comments
 (0)