Skip to content

Commit 51deec5

Browse files
authored
Merge pull request #2 from we-flow/structure-reformat
Scrollbar is in much better shape
2 parents d6a7b5a + 779e35d commit 51deec5

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

dist/index.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@
112112

113113
_this.onResize = _this.onResize.bind(_this);
114114
_this.onColumnResize = _this.onColumnResize.bind(_this);
115+
_this.setScrollBarWrapperDims = _this.setScrollBarWrapperDims.bind(_this);
115116
_this.onScrollX = _this.onScrollX.bind(_this);
116-
_this.scrollXScrollbar = _.debounce(_this.scrollXScrollbar.bind(_this), 100);
117-
_this.scrollYScrollbar = _.debounce(_this.scrollYScrollbar.bind(_this), 100);
117+
_this.scrollXScrollbar = _.throttle(_this.scrollXScrollbar.bind(_this), 30);
118+
_this.scrollYScrollbar = _.throttle(_this.scrollYScrollbar.bind(_this), 30);
118119
return _this;
119120
}
120121

@@ -139,6 +140,7 @@
139140

140141
this.onResize();
141142
this.addScrollBarEventHandlers();
143+
this.setScrollBarWrapperDims();
142144
}
143145
}
144146
}, {
@@ -191,11 +193,20 @@
191193
this.setColumnWidths();
192194
this.setScrollBarDims();
193195
}
196+
}, {
197+
key: 'setScrollBarWrapperDims',
198+
value: function setScrollBarWrapperDims() {
199+
this.xScrollbar.style.width = 'calc(100% - ' + this.stickyColumn.clientWidth + 'px)';
200+
this.xScrollbar.style.left = this.stickyColumn.clientWidth + 'px';
201+
202+
this.yScrollbar.style.height = 'calc(100% - ' + this.stickyHeader.clientHeight + 'px)';
203+
this.yScrollbar.style.top = this.stickyHeader.clientHeight + 'px';
204+
}
194205
}, {
195206
key: 'setScrollBarDims',
196207
value: function setScrollBarDims() {
197-
this.table.querySelector('#x-scrollbar div').style.width = this.getSizeWithoutBoxSizing(this.realTable.firstChild).width + 'px';
198-
this.table.querySelector('#y-scrollbar div').style.height = this.getSizeWithoutBoxSizing(this.realTable).height + 'px';
208+
this.xScrollbar.firstChild.style.width = this.getSizeWithoutBoxSizing(this.realTable.firstChild).width - this.stickyColumn.clientWidth + 'px';
209+
this.yScrollbar.firstChild.style.height = this.getSizeWithoutBoxSizing(this.realTable).height - this.stickyHeader.clientHeight + 'px';
199210
}
200211
}, {
201212
key: 'onColumnResize',
@@ -212,6 +223,7 @@
212223
}
213224

214225
this.onResize();
226+
this.setScrollBarWrapperDims();
215227
}
216228
}, {
217229
key: 'setRowHeights',

dist/react-sticky-table.css

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
height: 100%;
4444
overflow-y: auto;
4545
}
46+
/*
47+
Hack to make table paint on it's own layer.
48+
Because of this it won't paint when the scrollbar paints.
49+
This one was crucial for performance.
50+
Scrolling is probably 10-20x smoother.
51+
*/
52+
.sticky-table .sticky-table-x-wrapper .table{
53+
transform: translateZ(0);
54+
-webkit-transform: translateZ(0);
55+
}
4656

4757
/* Scrollbars */
4858
.sticky-table-y-wrapper::-webkit-scrollbar, .sticky-table-x-wrapper::-webkit-scrollbar {
@@ -53,6 +63,8 @@
5363
background-color: transparent;
5464
z-index: 5;
5565
overflow: auto;
66+
transform: translateZ(0);
67+
-webkit-transform: translateZ(0);
5668
}
5769
.sticky-table #x-scrollbar {
5870
left: 0px;

src/index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class StickyTable extends Component {
3030

3131
this.onResize = this.onResize.bind(this);
3232
this.onColumnResize = this.onColumnResize.bind(this);
33+
this.setScrollBarWrapperDims = this.setScrollBarWrapperDims.bind(this);
3334
this.onScrollX = this.onScrollX.bind(this);
34-
this.scrollXScrollbar = _.debounce(this.scrollXScrollbar.bind(this), 100);
35-
this.scrollYScrollbar = _.debounce(this.scrollYScrollbar.bind(this), 100);
35+
this.scrollXScrollbar = _.throttle(this.scrollXScrollbar.bind(this), 30);
36+
this.scrollYScrollbar = _.throttle(this.scrollYScrollbar.bind(this), 30);
3637
}
3738

3839
componentDidMount() {
@@ -54,6 +55,7 @@ class StickyTable extends Component {
5455

5556
this.onResize();
5657
this.addScrollBarEventHandlers();
58+
this.setScrollBarWrapperDims();
5759
}
5860
}
5961

@@ -106,9 +108,17 @@ class StickyTable extends Component {
106108
this.setScrollBarDims();
107109
}
108110

111+
setScrollBarWrapperDims() {
112+
this.xScrollbar.style.width = 'calc(100% - ' + this.stickyColumn.clientWidth + 'px)';
113+
this.xScrollbar.style.left = this.stickyColumn.clientWidth + 'px';
114+
115+
this.yScrollbar.style.height = 'calc(100% - ' + this.stickyHeader.clientHeight + 'px)';
116+
this.yScrollbar.style.top = this.stickyHeader.clientHeight + 'px';
117+
}
118+
109119
setScrollBarDims() {
110-
this.table.querySelector('#x-scrollbar div').style.width = this.getSizeWithoutBoxSizing(this.realTable.firstChild).width + 'px';
111-
this.table.querySelector('#y-scrollbar div').style.height = this.getSizeWithoutBoxSizing(this.realTable).height + 'px';
120+
this.xScrollbar.firstChild.style.width = (this.getSizeWithoutBoxSizing(this.realTable.firstChild).width - this.stickyColumn.clientWidth) + 'px';
121+
this.yScrollbar.firstChild.style.height = (this.getSizeWithoutBoxSizing(this.realTable).height - this.stickyHeader.clientHeight) + 'px';
112122
}
113123

114124
/**
@@ -128,6 +138,7 @@ class StickyTable extends Component {
128138
}
129139

130140
this.onResize();
141+
this.setScrollBarWrapperDims();
131142
}
132143

133144
/**

src/sticky-table.css

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
height: 100%;
3535
overflow-y: auto;
3636
}
37+
/*
38+
Hack to make table paint on it's own layer.
39+
Because of this it won't paint when the scrollbar paints.
40+
This one was crucial for performance.
41+
Scrolling is probably 10-20x smoother.
42+
*/
43+
.sticky-table .sticky-table-x-wrapper .table{
44+
transform: translateZ(0);
45+
-webkit-transform: translateZ(0);
46+
}
3747

3848
/* Scrollbars */
3949
.sticky-table-y-wrapper::-webkit-scrollbar, .sticky-table-x-wrapper::-webkit-scrollbar {
@@ -44,6 +54,8 @@
4454
background-color: transparent;
4555
z-index: 5;
4656
overflow: auto;
57+
transform: translateZ(0);
58+
-webkit-transform: translateZ(0);
4759
}
4860
.sticky-table #x-scrollbar {
4961
left: 0px;

0 commit comments

Comments
 (0)