Skip to content

Commit e9ae154

Browse files
committed
scroll fix
1 parent 1bff86e commit e9ae154

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

frontend/nextcp-ui/src/app/mediaserver/display-container/display-container.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,14 @@ export class DisplayContainerComponent {
293293
}
294294

295295
/**
296-
* @param elementID ATTENTION: elementID needs to have tabindex set to '-1': <div id="elementID" tabindex="-1">
296+
* Scrolls the element with this id to the top. Like CdsBrowsePathService.scrollIntoViewID, this
297+
* scrolls rather than focuses: a focused anchor is handed the focus back by every dialog that
298+
* closes afterwards, and the listing jumped to the top with it.
297299
*/
298300
public scrollIntoViewID(elementID: string): boolean {
299-
const targetElement = document.getElementById(elementID); // querySelector('#someElementId');
301+
const targetElement = document.getElementById(elementID);
300302
if (targetElement) {
301-
targetElement.focus();
303+
targetElement.scrollIntoView({ block: 'start' });
302304
console.log('scrolled to element ID : ' + elementID);
303305
return true;
304306
}

frontend/nextcp-ui/src/app/util/cds-browse-path.service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,23 @@ export class CdsBrowsePathService {
6464
public persistPathToRoot(): void {}
6565

6666
/**
67-
* @param elementID ATTENTION: elementID needs to have tabindex set to '-1': <div id="elementID" tabindex="-1">
67+
* Brings the element with this id to the top of the browse view.
68+
*
69+
* It used to get there by focusing the element, because focus() scrolls its target into view. That
70+
* also left the focus parked on the element - and every dialog opened afterwards handed the focus
71+
* back to it when it closed (MatDialog restores focus in ngOnDestroy), which scrolled the listing
72+
* to the top again. In a long list that is a jump from wherever the user was to the very first row,
73+
* on closing the song options, the rating sheet or the playlist picker. Scrolling directly moves
74+
* the listing and nothing else, so there is no focus left behind to come back to.
6875
*/
6976
public scrollIntoViewID(elementID?: string): void {
7077
if (!elementID) {
7178
elementID = this.scrollId();
7279
}
7380
console.log('[scroll] to ID : ' + elementID);
74-
const targetElement = document.getElementById(elementID); // querySelector('#someElementId');
81+
const targetElement = document.getElementById(elementID);
7582
if (targetElement) {
76-
targetElement.focus();
83+
targetElement.scrollIntoView({ block: 'start' });
7784
} else {
7885
console.log('[scroll] id not found : ' + elementID);
7986
}

0 commit comments

Comments
 (0)