@eclipse-scout/core
Version:
Eclipse Scout runtime
81 lines (71 loc) • 3.02 kB
text/typescript
/*
* Copyright (c) 2010, 2025 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
import {AbstractTableNavigationKeyStroke, aria, arrays, keys, Table, TableRow} from '../../index';
export class TableNavigationPageUpKeyStroke extends AbstractTableNavigationKeyStroke {
constructor(table: Table) {
super(table);
this.which = [keys.PAGE_UP];
this.renderingHints.text = 'PgUp';
this.renderingHints.$drawingArea = ($drawingArea, event) => {
return this._viewportInfo().firstRow?.$row;
};
}
override handle(event: JQuery.KeyboardEventBase) {
let table = this.field,
viewport = this._viewportInfo(),
rows = table.visibleRows,
selectedRows = table.selectedRows,
firstSelectedRow = arrays.first(selectedRows),
focusedRow = table.focusedRow,
focusedRowIndex = -1,
newSelectedRows: TableRow[];
// First row may be undefined if there is only one row visible in the viewport and this row is bigger than the viewport. In that case just scroll up.
// If it already is at the top nothing will happen
if (!viewport.firstRow) {
table.scrollPageUp();
viewport = this._viewportInfo();
if (!viewport.firstRow) {
return;
}
}
if (focusedRow) {
focusedRowIndex = rows.indexOf(focusedRow);
}
// focused row index maybe < 0 if row got invisible (e.g. due to filtering), or if the user has not made a selection before
if (focusedRowIndex < 0) {
focusedRow = firstSelectedRow;
focusedRowIndex = rows.indexOf(focusedRow);
}
// If first row in viewport already is selected -> scroll a page up
// Don't do it if multiple rows are selected and user only presses page up without shift
if (selectedRows.length > 0 && focusedRow === viewport.firstRow && !(selectedRows.length > 1 && !event.shiftKey)) {
table.scrollPageUp();
viewport = this._viewportInfo();
if (!viewport.firstRow) {
// May happen due to same reason as above -> Row will fill the whole viewport after scrolling
return;
}
}
if (event.shiftKey && selectedRows.length > 0) {
newSelectedRows = rows.slice(rows.indexOf(viewport.firstRow), focusedRowIndex);
newSelectedRows = arrays.union(selectedRows, newSelectedRows);
} else {
newSelectedRows = [viewport.firstRow];
}
table.setFocusedRow(viewport.firstRow);
table.selectRows(newSelectedRows, true);
if (!table.isFocused()) {
table.focus();
}
// Set active descendant to the new row. This should be done last so selection state/focus/etc. is
// all set correctly before the change of active descendant triggers the screen readers announcement.
aria.linkElementWithActiveDescendant(this.field.$container, viewport.firstRow.$row);
}
}