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

Fix tooltip overflowing to left #382

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cheetah-grid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cheetah-grid",
"version": "1.8.1",
"version": "1.8.2",
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
"keywords": [
"spreadsheet",
Expand Down
18 changes: 16 additions & 2 deletions packages/cheetah-grid/src/js/tooltip/internal/TooltipElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,31 @@ export class TooltipElement<T> {
return false; //範囲外
}
}
const { offsetHeight, offsetWidth } = element;
const {
height: offsetHeight,
width: offsetWidth,
left: elementLeft,
right: elementRight,
} = element.getBoundingClientRect();
if (offsetHeight < top) {
return false; //範囲外
}
if (offsetWidth < left) {
return false; //範囲外
}
const cellCenter = left + width / 2;

rootElement.style.top = `${top.toFixed()}px`;
rootElement.style.left = `${(left + width / 2).toFixed()}px`;
rootElement.style.left = `${cellCenter.toFixed()}px`;
rootElement.style.minWidth = `${width.toFixed()}px`;

const maxWidthForLeft = (elementLeft + cellCenter) * 2;
const winWidth = window.innerWidth;
const maxWidthForRight =
(offsetWidth - cellCenter + (winWidth - elementRight)) * 2;
const maxWidth = Math.min(maxWidthForLeft, maxWidthForRight);
rootElement.style.maxWidth = `${maxWidth.toFixed()}px`;

if (rootElement.parentElement !== element) {
element.appendChild(rootElement);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-cheetah-grid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-cheetah-grid",
"version": "1.8.1",
"version": "1.8.2",
"description": "Cheetah Grid for Vue.js",
"main": "lib/index.js",
"unpkg": "dist/vueCheetahGrid.js",
Expand Down