@ni/ok-components 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -73304,25 +73304,32 @@ focus outline in that case.
|
|
|
73304
73304
|
this.columnIndex = -1;
|
|
73305
73305
|
this.focusWithinTable = false;
|
|
73306
73306
|
this.isCurrentlyFocusingElement = false;
|
|
73307
|
+
this.focusedViaPointer = false;
|
|
73307
73308
|
this.visibleRowNotifiers = [];
|
|
73308
73309
|
this.onTableFocusIn = (event) => {
|
|
73309
73310
|
this.focusWithinTable = true;
|
|
73310
|
-
this.updateFocusStateFromActiveElement(
|
|
73311
|
+
this.updateFocusStateFromActiveElement();
|
|
73311
73312
|
// Sets initial focus on the appropriate table content
|
|
73312
73313
|
const actionMenuOpen = this.table.openActionMenuRecordId !== undefined;
|
|
73313
|
-
if (
|
|
73314
|
-
|
|
73315
|
-
|
|
73316
|
-
let focusHeader = true;
|
|
73317
|
-
if (this.hasRowOrCellFocusType()
|
|
73318
|
-
&& this.scrollToAndFocusRow(this.rowIndex)) {
|
|
73319
|
-
focusHeader = false;
|
|
73314
|
+
if (!actionMenuOpen) {
|
|
73315
|
+
if (this.focusType === TableFocusType.none) {
|
|
73316
|
+
this.focusSomethingOtherThanTheTable();
|
|
73320
73317
|
}
|
|
73321
|
-
if (
|
|
73322
|
-
//
|
|
73323
|
-
this.
|
|
73318
|
+
else if (event.target === this.table) {
|
|
73319
|
+
// restore focus to last focused element
|
|
73320
|
+
if (this.hasRowOrCellFocusType() && this.rowIndexIsValid(this.rowIndex)) {
|
|
73321
|
+
this.scrollToAndFocusRow(this.rowIndex);
|
|
73322
|
+
}
|
|
73323
|
+
else if (this.hasHeaderFocusType()) {
|
|
73324
|
+
this.focusHeaderElement();
|
|
73325
|
+
}
|
|
73326
|
+
else {
|
|
73327
|
+
// should only get here if focusType was row/cell, but rowIndex was invalid
|
|
73328
|
+
this.focusSomethingOtherThanTheTable();
|
|
73329
|
+
}
|
|
73324
73330
|
}
|
|
73325
73331
|
}
|
|
73332
|
+
this.focusedViaPointer = false;
|
|
73326
73333
|
};
|
|
73327
73334
|
this.onTableFocusOut = () => {
|
|
73328
73335
|
this.focusWithinTable = false;
|
|
@@ -73337,12 +73344,18 @@ focus outline in that case.
|
|
|
73337
73344
|
};
|
|
73338
73345
|
this.onCellViewFocusIn = (event) => {
|
|
73339
73346
|
event.stopPropagation();
|
|
73340
|
-
this.updateFocusStateFromActiveElement(
|
|
73347
|
+
this.updateFocusStateFromActiveElement();
|
|
73341
73348
|
};
|
|
73342
73349
|
this.onCellFocusIn = (event) => {
|
|
73343
73350
|
event.stopPropagation();
|
|
73344
73351
|
const cell = event.detail;
|
|
73345
|
-
this.updateFocusStateFromActiveElement(
|
|
73352
|
+
const row = this.updateFocusStateFromActiveElement();
|
|
73353
|
+
if (row) {
|
|
73354
|
+
if (this.hasRowOrCellFocusType()
|
|
73355
|
+
&& this.rowIndex !== row.resolvedRowIndex) {
|
|
73356
|
+
this.setRowFocusState(row.resolvedRowIndex);
|
|
73357
|
+
}
|
|
73358
|
+
}
|
|
73346
73359
|
// Currently, clicking a non-interactive cell only updates the focus state to that row, it
|
|
73347
73360
|
// doesn't focus the cell. If we revisit this, we most likely need to set the cells to tabindex=-1
|
|
73348
73361
|
// upfront too, so their focusing behavior is consistent whether they've been previously keyboard
|
|
@@ -73413,6 +73426,12 @@ focus outline in that case.
|
|
|
73413
73426
|
}
|
|
73414
73427
|
}
|
|
73415
73428
|
};
|
|
73429
|
+
this.onPointerDown = () => {
|
|
73430
|
+
this.focusedViaPointer = true;
|
|
73431
|
+
};
|
|
73432
|
+
this.onPointerUpOrCancel = () => {
|
|
73433
|
+
this.focusedViaPointer = false;
|
|
73434
|
+
};
|
|
73416
73435
|
this.onViewportKeyDown = (event) => {
|
|
73417
73436
|
let handleEvent = !this.inNavigationMode
|
|
73418
73437
|
&& (event.key === keyArrowUp || event.key === keyArrowDown);
|
|
@@ -73448,6 +73467,9 @@ focus outline in that case.
|
|
|
73448
73467
|
connect() {
|
|
73449
73468
|
this.table.addEventListener('keydown', this.onCaptureKeyDown, { capture: true });
|
|
73450
73469
|
this.table.addEventListener('keydown', this.onKeyDown);
|
|
73470
|
+
this.table.addEventListener('pointerdown', this.onPointerDown);
|
|
73471
|
+
this.table.addEventListener('pointerup', this.onPointerUpOrCancel);
|
|
73472
|
+
this.table.addEventListener('pointercancel', this.onPointerUpOrCancel);
|
|
73451
73473
|
this.table.addEventListener('focusin', this.onTableFocusIn);
|
|
73452
73474
|
this.table.addEventListener('focusout', this.onTableFocusOut);
|
|
73453
73475
|
this.table.viewport.addEventListener('keydown', this.onViewportKeyDown);
|
|
@@ -73459,6 +73481,9 @@ focus outline in that case.
|
|
|
73459
73481
|
disconnect() {
|
|
73460
73482
|
this.table.removeEventListener('keydown', this.onCaptureKeyDown, { capture: true });
|
|
73461
73483
|
this.table.removeEventListener('keydown', this.onKeyDown);
|
|
73484
|
+
this.table.removeEventListener('pointerdown', this.onPointerDown);
|
|
73485
|
+
this.table.removeEventListener('pointerup', this.onPointerUpOrCancel);
|
|
73486
|
+
this.table.removeEventListener('pointercancel', this.onPointerUpOrCancel);
|
|
73462
73487
|
this.table.removeEventListener('focusin', this.onTableFocusIn);
|
|
73463
73488
|
this.table.removeEventListener('focusout', this.onTableFocusOut);
|
|
73464
73489
|
this.table.viewport.removeEventListener('keydown', this.onViewportKeyDown);
|
|
@@ -73550,6 +73575,13 @@ focus outline in that case.
|
|
|
73550
73575
|
this.setCellActionMenuFocusState(row.resolvedRowIndex, columnIndex, false);
|
|
73551
73576
|
}
|
|
73552
73577
|
}
|
|
73578
|
+
focusSomethingOtherThanTheTable() {
|
|
73579
|
+
this.setDefaultFocus();
|
|
73580
|
+
if (this.focusType === TableFocusType.none) {
|
|
73581
|
+
// nothing within the table to focus
|
|
73582
|
+
this.table.blur();
|
|
73583
|
+
}
|
|
73584
|
+
}
|
|
73553
73585
|
onEnterPressed(ctrlKey) {
|
|
73554
73586
|
let row;
|
|
73555
73587
|
let rowElements;
|
|
@@ -73721,7 +73753,7 @@ focus outline in that case.
|
|
|
73721
73753
|
this.headerActionIndex = nextFocusState.headerActionIndex ?? this.headerActionIndex;
|
|
73722
73754
|
this.cellContentIndex = nextFocusState.cellContentIndex ?? this.cellContentIndex;
|
|
73723
73755
|
if (this.hasRowOrCellFocusType()) {
|
|
73724
|
-
this.focusCurrentRow(
|
|
73756
|
+
this.focusCurrentRow(!this.focusedViaPointer);
|
|
73725
73757
|
}
|
|
73726
73758
|
else {
|
|
73727
73759
|
this.focusHeaderElement();
|
|
@@ -73893,35 +73925,39 @@ focus outline in that case.
|
|
|
73893
73925
|
}
|
|
73894
73926
|
return false;
|
|
73895
73927
|
}
|
|
73896
|
-
updateFocusStateFromActiveElement(
|
|
73928
|
+
updateFocusStateFromActiveElement() {
|
|
73897
73929
|
// If the user is interacting with the table with non-keyboard methods (like mouse), we need to
|
|
73898
73930
|
// update our focus state based on the current active/focused element
|
|
73899
|
-
const activeElement = this.
|
|
73900
|
-
if (
|
|
73901
|
-
|
|
73902
|
-
|
|
73903
|
-
|
|
73904
|
-
|
|
73905
|
-
|
|
73906
|
-
|
|
73907
|
-
|
|
73908
|
-
|
|
73909
|
-
|
|
73910
|
-
|
|
73911
|
-
const contentIndex = cell.cellView.tabbableChildren.indexOf(activeElement);
|
|
73912
|
-
if (contentIndex > -1) {
|
|
73913
|
-
this.setCellContentFocusState(contentIndex, row.resolvedRowIndex, columnIndex, false);
|
|
73914
|
-
return;
|
|
73915
|
-
}
|
|
73916
|
-
}
|
|
73917
|
-
}
|
|
73918
|
-
if (setRowFocus
|
|
73919
|
-
&& this.hasRowOrCellFocusType()
|
|
73920
|
-
&& this.rowIndex !== row.resolvedRowIndex) {
|
|
73921
|
-
this.setRowFocusState(row.resolvedRowIndex);
|
|
73922
|
-
}
|
|
73931
|
+
const { activeElement, row, cell } = this.getActiveElementCellAndRow();
|
|
73932
|
+
if (!cell) {
|
|
73933
|
+
return row;
|
|
73934
|
+
}
|
|
73935
|
+
const columnIndex = this.table.visibleColumns.indexOf(cell.column);
|
|
73936
|
+
if (cell.actionMenuButton === activeElement) {
|
|
73937
|
+
this.setCellActionMenuFocusState(row.resolvedRowIndex, columnIndex, false);
|
|
73938
|
+
}
|
|
73939
|
+
else {
|
|
73940
|
+
const contentIndex = cell.cellView.tabbableChildren.indexOf(activeElement);
|
|
73941
|
+
if (contentIndex > -1) {
|
|
73942
|
+
this.setCellContentFocusState(contentIndex, row.resolvedRowIndex, columnIndex, false);
|
|
73923
73943
|
}
|
|
73924
73944
|
}
|
|
73945
|
+
return row;
|
|
73946
|
+
}
|
|
73947
|
+
getActiveElementCellAndRow() {
|
|
73948
|
+
const activeElement = this.getActiveElement();
|
|
73949
|
+
if (!activeElement) {
|
|
73950
|
+
return {};
|
|
73951
|
+
}
|
|
73952
|
+
const row = this.getContainingRow(activeElement);
|
|
73953
|
+
if (!row) {
|
|
73954
|
+
return { activeElement };
|
|
73955
|
+
}
|
|
73956
|
+
if (row instanceof TableGroupRow) {
|
|
73957
|
+
return { activeElement, row };
|
|
73958
|
+
}
|
|
73959
|
+
const cell = this.getContainingCell(activeElement);
|
|
73960
|
+
return { activeElement, row, cell };
|
|
73925
73961
|
}
|
|
73926
73962
|
focusElement(element, focusOptions) {
|
|
73927
73963
|
const previousActiveElement = this.getActiveElement();
|
|
@@ -73952,13 +73988,6 @@ focus outline in that case.
|
|
|
73952
73988
|
menuButton.classList.remove('cell-action-menu-focused');
|
|
73953
73989
|
}
|
|
73954
73990
|
}
|
|
73955
|
-
setFocusOnHeader() {
|
|
73956
|
-
if (this.hasHeaderFocusType()) {
|
|
73957
|
-
return this.focusHeaderElement();
|
|
73958
|
-
}
|
|
73959
|
-
this.setDefaultFocus();
|
|
73960
|
-
return this.focusType !== TableFocusType.none;
|
|
73961
|
-
}
|
|
73962
73991
|
setDefaultFocus() {
|
|
73963
73992
|
const headerElements = this.getTableHeaderFocusableElements();
|
|
73964
73993
|
if (!this.trySetHeaderActionFocus(headerElements, 0)
|
|
@@ -73968,20 +73997,19 @@ focus outline in that case.
|
|
|
73968
73997
|
}
|
|
73969
73998
|
}
|
|
73970
73999
|
scrollToAndFocusRow(totalRowIndex, scrollOptions) {
|
|
73971
|
-
if (
|
|
73972
|
-
|
|
73973
|
-
case TableFocusType.none:
|
|
73974
|
-
case TableFocusType.headerActions:
|
|
73975
|
-
case TableFocusType.columnHeader:
|
|
73976
|
-
this.setRowFocusState(totalRowIndex);
|
|
73977
|
-
break;
|
|
73978
|
-
}
|
|
73979
|
-
this.rowIndex = totalRowIndex;
|
|
73980
|
-
this.virtualizer.scrollToIndex(totalRowIndex, scrollOptions);
|
|
73981
|
-
this.focusCurrentRow(true);
|
|
73982
|
-
return true;
|
|
74000
|
+
if (!this.rowIndexIsValid(totalRowIndex)) {
|
|
74001
|
+
return false;
|
|
73983
74002
|
}
|
|
73984
|
-
|
|
74003
|
+
if (!this.hasRowOrCellFocusType()) {
|
|
74004
|
+
this.setRowFocusState();
|
|
74005
|
+
}
|
|
74006
|
+
this.rowIndex = totalRowIndex;
|
|
74007
|
+
this.virtualizer.scrollToIndex(totalRowIndex, scrollOptions);
|
|
74008
|
+
this.focusCurrentRow(!this.focusedViaPointer);
|
|
74009
|
+
return true;
|
|
74010
|
+
}
|
|
74011
|
+
rowIndexIsValid(rowIndex) {
|
|
74012
|
+
return rowIndex >= 0 && rowIndex < this.table.tableData.length;
|
|
73985
74013
|
}
|
|
73986
74014
|
focusCurrentRow(allowScroll) {
|
|
73987
74015
|
const visibleRowIndex = this.getCurrentRowVisibleIndex();
|
|
@@ -74049,7 +74077,7 @@ focus outline in that case.
|
|
|
74049
74077
|
break;
|
|
74050
74078
|
}
|
|
74051
74079
|
if (focusableElement) {
|
|
74052
|
-
this.focusElement(focusableElement);
|
|
74080
|
+
this.focusElement(focusableElement, { preventScroll: this.focusedViaPointer });
|
|
74053
74081
|
return true;
|
|
74054
74082
|
}
|
|
74055
74083
|
return false;
|
|
@@ -74170,7 +74198,7 @@ focus outline in that case.
|
|
|
74170
74198
|
trySetRowSelectionCheckboxFocus(rowElements) {
|
|
74171
74199
|
if (rowElements?.selectionCheckbox) {
|
|
74172
74200
|
this.focusType = TableFocusType.rowSelectionCheckbox;
|
|
74173
|
-
this.focusCurrentRow(
|
|
74201
|
+
this.focusCurrentRow(!this.focusedViaPointer);
|
|
74174
74202
|
return true;
|
|
74175
74203
|
}
|
|
74176
74204
|
return false;
|
|
@@ -74259,7 +74287,7 @@ focus outline in that case.
|
|
|
74259
74287
|
this.rowIndex = rowIndex;
|
|
74260
74288
|
this.columnIndex = columnIndex;
|
|
74261
74289
|
if (focusElement) {
|
|
74262
|
-
this.focusCurrentRow(
|
|
74290
|
+
this.focusCurrentRow(!this.focusedViaPointer);
|
|
74263
74291
|
}
|
|
74264
74292
|
}
|
|
74265
74293
|
isResolvedRowType(row) {
|