Skip to content

Commit 0404b3e

Browse files
committed
fix: sync view headers with scroll
1 parent c0ca3e2 commit 0404b3e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/dashboard/Data/Views/Views.react.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Views extends TableView {
2626
super();
2727
this.section = 'Core';
2828
this.subsection = 'Views';
29+
this.contentRef = React.createRef();
30+
this.headerRef = React.createRef();
31+
this.syncHeaderPosition = this.syncHeaderPosition.bind(this);
2932
this.state = {
3033
views: [],
3134
counts: {},
@@ -49,6 +52,21 @@ class Views extends TableView {
4952
.then(() => this.loadViews(this.context));
5053
}
5154

55+
componentDidMount() {
56+
this.syncHeaderPosition();
57+
window.addEventListener('scroll', this.syncHeaderPosition);
58+
window.addEventListener('resize', this.syncHeaderPosition);
59+
}
60+
61+
componentDidUpdate() {
62+
this.syncHeaderPosition();
63+
}
64+
65+
componentWillUnmount() {
66+
window.removeEventListener('scroll', this.syncHeaderPosition);
67+
window.removeEventListener('resize', this.syncHeaderPosition);
68+
}
69+
5270
componentWillReceiveProps(nextProps, nextContext) {
5371
if (this.context !== nextContext) {
5472
this.props.schema
@@ -174,12 +192,13 @@ class Views extends TableView {
174192
return (
175193
<div>
176194
<LoaderContainer loading={loading}>
177-
<div className={tableStyles.content}>{content}</div>
195+
<div className={tableStyles.content} ref={this.contentRef}>{content}</div>
178196
</LoaderContainer>
179197
{toolbar}
180198
<div
181199
className={tableStyles.headers}
182200
style={{ width: this.state.tableWidth, right: 'auto' }}
201+
ref={this.headerRef}
183202
>
184203
{headers}
185204
</div>
@@ -332,6 +351,14 @@ class Views extends TableView {
332351
this.props.navigate(path);
333352
}
334353

354+
syncHeaderPosition() {
355+
if (!this.headerRef.current || !this.contentRef.current) {
356+
return;
357+
}
358+
const left = this.contentRef.current.getBoundingClientRect().left;
359+
this.headerRef.current.style.left = `${left}px`;
360+
}
361+
335362
showNote(message, isError) {
336363
if (!message) {
337364
return;

0 commit comments

Comments
 (0)