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

Commit cc49e64

Browse files
authored
Merge pull request #4961 from matrix-org/t3chguy/room-list/14273
Fix room sub list header collapse/jump interactions on bottom-most sublist
2 parents 68948d4 + fd8f43e commit cc49e64

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/components/views/rooms/RoomSublist2.tsx

+15-11
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,29 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
321321
}
322322
};
323323

324-
private onHeaderClick = (ev: React.MouseEvent<HTMLDivElement>) => {
325-
let target = ev.target as HTMLDivElement;
326-
if (!target.classList.contains('mx_RoomSublist2_headerText')) {
327-
// If we don't have the headerText class, the user clicked the span in the headerText.
328-
target = target.parentElement as HTMLDivElement;
329-
}
330-
331-
const possibleSticky = target.parentElement;
324+
private onHeaderClick = () => {
325+
const possibleSticky = this.headerButton.current.parentElement;
332326
const sublist = possibleSticky.parentElement.parentElement;
333327
const list = sublist.parentElement.parentElement;
334-
// the scrollTop is capped at the height of the header in LeftPanel2
328+
// the scrollTop is capped at the height of the header in LeftPanel2, the top header is always sticky
335329
const isAtTop = list.scrollTop <= HEADER_HEIGHT;
336-
const isSticky = possibleSticky.classList.contains('mx_RoomSublist2_headerContainer_sticky');
337-
if (isSticky && !isAtTop) {
330+
const isAtBottom = list.scrollTop >= list.scrollHeight - list.offsetHeight;
331+
const isStickyTop = possibleSticky.classList.contains('mx_RoomSublist2_headerContainer_stickyTop');
332+
const isStickyBottom = possibleSticky.classList.contains('mx_RoomSublist2_headerContainer_stickyBottom');
333+
334+
if ((isStickyBottom && !isAtBottom) || (isStickyTop && !isAtTop)) {
338335
// is sticky - jump to list
339336
sublist.scrollIntoView({behavior: 'smooth'});
340337
} else {
341338
// on screen - toggle collapse
339+
const isExpanded = this.state.isExpanded;
342340
this.toggleCollapsed();
341+
// if the bottom list is collapsed then scroll it in so it doesn't expand off screen
342+
if (!isExpanded && isStickyBottom) {
343+
setImmediate(() => {
344+
sublist.scrollIntoView({behavior: 'smooth'});
345+
});
346+
}
343347
}
344348
};
345349

0 commit comments

Comments
 (0)