Skip to content

Commit

Permalink
Fix scroll width calculation fail (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Oct 4, 2022
1 parent e1839fd commit 6b7be4d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
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.2",
"version": "1.8.3",
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
"keywords": [
"spreadsheet",
Expand Down
36 changes: 21 additions & 15 deletions packages/cheetah-grid/src/js/internal/style.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
function getScrollBarWidth(): number {
const dummy = document.createElement("div");
const { style } = dummy;
style.position = "absolute";
style.height = "9999px";
style.width = "calc(100vw - 100%)";
style.opacity = "0";
dummy.textContent = "x";
document.body.appendChild(dummy);
const { width } = (document.defaultView || window).getComputedStyle(
dummy,
""
);
document.body.removeChild(dummy);
return parseInt(width, 10);
function getScrollBarWidth() {
const wrapper = document.createElement("div");
const inner = document.createElement("div");
const { style: wrapperStyle } = wrapper;
wrapperStyle.position = "fixed";
wrapperStyle.height = "50px";
wrapperStyle.width = "50px";
wrapperStyle.overflow = "scroll";
wrapperStyle.opacity = "0";
wrapperStyle.pointerEvents = "none";

const { style } = inner;
style.height = "100%";
style.width = "100%";
inner.textContent = "x";
wrapper.appendChild(inner);
document.body.appendChild(wrapper);
const wrapperWidth = wrapper.getBoundingClientRect().width;
const innerWidth = inner.getBoundingClientRect().width;
document.body.removeChild(wrapper);
return Math.ceil(wrapperWidth - innerWidth);
}

let SCROLLBAR_SIZE: number;
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.2",
"version": "1.8.3",
"description": "Cheetah Grid for Vue.js",
"main": "lib/index.js",
"unpkg": "dist/vueCheetahGrid.js",
Expand Down

0 comments on commit 6b7be4d

Please sign in to comment.