Skip to content

Commit 6b7be4d

Browse files
authored
Fix scroll width calculation fail (#385)
1 parent e1839fd commit 6b7be4d

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

packages/cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "1.8.2",
3+
"version": "1.8.3",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/internal/style.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
function getScrollBarWidth(): number {
2-
const dummy = document.createElement("div");
3-
const { style } = dummy;
4-
style.position = "absolute";
5-
style.height = "9999px";
6-
style.width = "calc(100vw - 100%)";
7-
style.opacity = "0";
8-
dummy.textContent = "x";
9-
document.body.appendChild(dummy);
10-
const { width } = (document.defaultView || window).getComputedStyle(
11-
dummy,
12-
""
13-
);
14-
document.body.removeChild(dummy);
15-
return parseInt(width, 10);
1+
function getScrollBarWidth() {
2+
const wrapper = document.createElement("div");
3+
const inner = document.createElement("div");
4+
const { style: wrapperStyle } = wrapper;
5+
wrapperStyle.position = "fixed";
6+
wrapperStyle.height = "50px";
7+
wrapperStyle.width = "50px";
8+
wrapperStyle.overflow = "scroll";
9+
wrapperStyle.opacity = "0";
10+
wrapperStyle.pointerEvents = "none";
11+
12+
const { style } = inner;
13+
style.height = "100%";
14+
style.width = "100%";
15+
inner.textContent = "x";
16+
wrapper.appendChild(inner);
17+
document.body.appendChild(wrapper);
18+
const wrapperWidth = wrapper.getBoundingClientRect().width;
19+
const innerWidth = inner.getBoundingClientRect().width;
20+
document.body.removeChild(wrapper);
21+
return Math.ceil(wrapperWidth - innerWidth);
1622
}
1723

1824
let SCROLLBAR_SIZE: number;

packages/vue-cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cheetah-grid",
3-
"version": "1.8.2",
3+
"version": "1.8.3",
44
"description": "Cheetah Grid for Vue.js",
55
"main": "lib/index.js",
66
"unpkg": "dist/vueCheetahGrid.js",

0 commit comments

Comments
 (0)