@@ -321,25 +321,29 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
321
321
}
322
322
} ;
323
323
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 ;
332
326
const sublist = possibleSticky . parentElement . parentElement ;
333
327
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
335
329
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 ) ) {
338
335
// is sticky - jump to list
339
336
sublist . scrollIntoView ( { behavior : 'smooth' } ) ;
340
337
} else {
341
338
// on screen - toggle collapse
339
+ const isExpanded = this . state . isExpanded ;
342
340
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
+ }
343
347
}
344
348
} ;
345
349
0 commit comments