-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathTableRowBase.ts
More file actions
132 lines (105 loc) · 3.32 KB
/
TableRowBase.ts
File metadata and controls
132 lines (105 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import { customElement, property, i18n } from "@ui5/webcomponents-base/dist/decorators.js";
import { isEnter, isSpace } from "@ui5/webcomponents-base/dist/Keys.js";
import { isInstanceOfTable, toggleAttribute } from "./TableUtils.js";
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
import TableRowBaseCss from "./generated/themes/TableRowBase.css.js";
import query from "@ui5/webcomponents-base/dist/decorators/query.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type TableCellBase from "./TableCellBase.js";
import type Table from "./Table.js";
import {
TABLE_ROW_SELECTOR,
} from "./generated/i18n/i18n-defaults.js";
/**
* @class
* A class to serve as a foundation for the `TableRow` and `TableHeaderRow` classes.
* @constructor
* @abstract
* @extends UI5Element
* @since 2.0.0
* @public
*/
@customElement({
renderer: jsxRenderer,
styles: TableRowBaseCss,
})
abstract class TableRowBase<TCell extends TableCellBase = TableCellBase> extends UI5Element {
eventDetails!: {
click: void
}
cells!: Array<TCell>;
@property({ type: Number, noAttribute: true })
_invalidate = 0;
@property({ type: Number, noAttribute: true })
_rowActionCount = 0;
@property({ type: Boolean, noAttribute: true })
_renderNavigated = false;
@property({ type: Boolean, noAttribute: true })
_alternate = false;
@query("#selection-cell")
_selectionCell?: HTMLElement;
@query("#navigated-cell")
_navigatedCell?: HTMLElement;
@i18n("@ui5/webcomponents")
static i18nBundle: I18nBundle;
onEnterDOM() {
!this.role && this.setAttribute("role", "row");
this.toggleAttribute("ui5-table-row-base", true);
}
onBeforeRendering() {
toggleAttribute(this, "aria-selected", this._isSelectable, `${this._isSelected}`);
}
getFocusDomRef() {
return this;
}
isHeaderRow(): boolean {
return false;
}
_onSelectionChange() {
const tableSelection = this._tableSelection!;
const selected = tableSelection.isMultiSelectable() ? !this._isSelected : true;
tableSelection.setSelected(this, selected, true);
}
_onkeydown(e: KeyboardEvent, eventOrigin: HTMLElement) {
if ((eventOrigin === this && this._isSelectable && isSpace(e)) || (eventOrigin === this._selectionCell && (isSpace(e) || isEnter(e)))) {
this._onSelectionChange();
e.preventDefault();
}
}
get _table(): Table | undefined {
const element = this.parentElement;
return isInstanceOfTable(element) ? element : undefined;
}
get _tableId() {
return this._table?._id;
}
get _tableSelection() {
return this._table?._getSelection();
}
get _isSelected() {
return this._tableSelection?.isSelected(this);
}
get _isSelectable() {
return this._tableSelection?.isSelectable();
}
get _isMultiSelect() {
return !!this._tableSelection?.isMultiSelectable();
}
get _hasSelector() {
return this._table?._isRowSelectorRequired;
}
get _visibleCells() {
return this.cells.filter(c => !c._popin);
}
get _popinCells() {
return this.cells.filter(c => c._popin && !c._popinHidden);
}
get _stickyCells() {
return [this._selectionCell, ...this.cells, this._navigatedCell].filter(cell => cell?.hasAttribute("fixed"));
}
get _i18nRowSelector(): string {
return TableRowBase.i18nBundle.getText(TABLE_ROW_SELECTOR);
}
}
export default TableRowBase;