Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 29c1c8d

Browse files
authored
Fix ScrollPanel data-scrollbar not responding to window resizing (#7841)
1 parent 6fccd6b commit 29c1c8d

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/components/structures/AutoHideScrollbar.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ export default class AutoHideScrollbar extends React.Component<IProps> {
4747
}
4848
}
4949

50-
public getScrollTop(): number {
51-
return this.containerRef.current.scrollTop;
52-
}
53-
5450
public render() {
5551
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5652
const { className, onScroll, onWheel, style, tabIndex, wrappedRef, children, ...otherProps } = this.props;

src/components/structures/ScrollPanel.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { replaceableComponent } from "../../utils/replaceableComponent";
2323
import { getKeyBindingsManager } from "../../KeyBindingsManager";
2424
import ResizeNotifier from "../../utils/ResizeNotifier";
2525
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
26+
import UIStore, { UI_EVENTS } from "../../stores/UIStore";
2627

2728
const DEBUG_SCROLL = false;
2829

@@ -214,6 +215,8 @@ export default class ScrollPanel extends React.Component<IProps> {
214215

215216
componentDidMount() {
216217
this.checkScroll();
218+
219+
UIStore.instance.on(UI_EVENTS.Resize, this.onUiResize);
217220
}
218221

219222
componentDidUpdate() {
@@ -236,6 +239,8 @@ export default class ScrollPanel extends React.Component<IProps> {
236239
if (this.props.resizeNotifier) {
237240
this.props.resizeNotifier.removeListener("middlePanelResizedNoisy", this.onResize);
238241
}
242+
243+
UIStore.instance.off(UI_EVENTS.Resize, this.onUiResize);
239244
}
240245

241246
private onScroll = ev => {
@@ -730,6 +735,17 @@ export default class ScrollPanel extends React.Component<IProps> {
730735
}
731736
}
732737

738+
private onUiResize = () => {
739+
this.setDataScrollbar();
740+
};
741+
742+
private setDataScrollbar(contentHeight = this.getMessagesHeight()) {
743+
const sn = this.getScrollNode();
744+
const minHeight = sn.clientHeight;
745+
const displayScrollbar = contentHeight > minHeight;
746+
sn.dataset.scrollbar = displayScrollbar.toString();
747+
}
748+
733749
// need a better name that also indicates this will change scrollTop? Rebalance height? Reveal content?
734750
private async updateHeight(): Promise<void> {
735751
// wait until user has stopped scrolling
@@ -751,8 +767,7 @@ export default class ScrollPanel extends React.Component<IProps> {
751767
const minHeight = sn.clientHeight;
752768
const height = Math.max(minHeight, contentHeight);
753769
this.pages = Math.ceil(height / PAGE_SIZE);
754-
const displayScrollbar = contentHeight > minHeight;
755-
sn.dataset.scrollbar = displayScrollbar.toString();
770+
this.setDataScrollbar(contentHeight);
756771
this.bottomGrowth = 0;
757772
const newHeight = `${this.getListHeight()}px`;
758773

0 commit comments

Comments
 (0)