lightning-base-components 1.21.3-alpha → 1.21.5-alpha
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.
- package/metadata/raptor.json +49 -0
- package/package.json +96 -21
- package/scopedImports/@salesforce-label-LightningDatatable.showActions.js +1 -1
- package/scopedImports/@salesforce-label-LightningForm.controllerFieldsMessage.js +1 -0
- package/scopedImports/@salesforce-label-LightningForm.dependentFieldsHeader.js +1 -0
- package/scopedImports/@salesforce-label-LightningForm.dependentFieldsListHeading.js +1 -0
- package/scopedImports/@salesforce-label-LightningForm.generalDependentFieldsMessage.js +1 -0
- package/scopedImports/@salesforce-label-LightningForm.learnMore.js +1 -0
- package/scopedImports/@salesforce-label-LightningForm.okButton.js +1 -0
- package/scopedImports/@salesforce-label-LightningLookup.messageWhenSearchTermTooShort.js +1 -0
- package/scopedImports/@salesforce-label-LightningLookup.modalCancel.js +1 -0
- package/scopedImports/@salesforce-label-LightningLookup.modalSelect.js +1 -0
- package/scopedImports/@salesforce-label-LightningProgressIndicator.currentStage.js +1 -1
- package/scopedImports/@salesforce-label-LightningProgressIndicator.errorStage.js +1 -0
- package/scopedImports/@salesforce-label-LightningProgressIndicator.stageComplete.js +1 -1
- package/scopedImports/@salesforce-label-LightningProgressIndicator.stageNotStarted.js +1 -1
- package/src/lightning/accordion/__docs__/accordion.md +0 -4
- package/src/lightning/accordionSection/__docs__/accordionSection.md +0 -4
- package/src/lightning/avatar/__docs__/avatar.md +0 -4
- package/src/lightning/avatar/avatar.html +1 -0
- package/src/lightning/badge/__docs__/badge.md +0 -4
- package/src/lightning/badge/badge.html +3 -3
- package/src/lightning/barcodeScanner/__docs__/barcodeScanner.md +0 -4
- package/src/lightning/baseCombobox/baseCombobox.html +4 -1
- package/src/lightning/baseCombobox/baseCombobox.js +5 -18
- package/src/lightning/baseComboboxItem/baseComboboxItem.js +6 -10
- package/src/lightning/button/__docs__/button.md +5 -8
- package/src/lightning/button/button.js +3 -4
- package/src/lightning/buttonGroup/__docs__/buttonGroup.md +0 -4
- package/src/lightning/buttonIcon/__docs__/buttonIcon.md +1 -4
- package/src/lightning/buttonIcon/buttonIcon.html +1 -1
- package/src/lightning/buttonIcon/buttonIcon.js +18 -17
- package/src/lightning/buttonIconStateful/__docs__/buttonIconStateful.md +0 -4
- package/src/lightning/buttonMenu/__docs__/buttonMenu.md +0 -4
- package/src/lightning/buttonMenu/buttonMenu.css +5 -0
- package/src/lightning/buttonMenu/buttonMenu.js +2 -0
- package/src/lightning/buttonStateful/__docs__/buttonStateful.md +0 -4
- package/src/lightning/buttonStateful/buttonStateful.html +5 -3
- package/src/lightning/buttonStateful/buttonStateful.js +4 -0
- package/src/lightning/card/__docs__/card.md +0 -4
- package/src/lightning/card/card.js-meta.xml +3 -0
- package/src/lightning/carousel/__docs__/carousel.md +0 -4
- package/src/lightning/checkboxGroup/__docs__/checkboxGroup.md +0 -4
- package/src/lightning/colorPickerCustom/colorPickerCustom.js +12 -0
- package/src/lightning/colorPickerPanel/colorPickerPanel.js +11 -1
- package/src/lightning/combobox/__docs__/combobox.md +0 -4
- package/src/lightning/combobox/combobox.html +1 -0
- package/src/lightning/datatable/__examples__disabled/customComponentWrapper/customComponentWrapper.html +11 -0
- package/src/lightning/datatable/__examples__disabled/customComponentWrapper/customComponentWrapper.js +25 -0
- package/src/lightning/datatable/__examples__disabled/customComponentWrapper/generateData.js +15 -0
- package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/customInput.html +4 -0
- package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/myCustomTypeDatatable.js +17 -0
- package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/nestedSimpleComponentParent.html +7 -0
- package/src/lightning/datatable/__examples__disabled/simpleComponentNested/simpleComponentNested.html +9 -0
- package/src/lightning/datatable/__examples__disabled/simpleComponentNested/simpleComponentNested.js +6 -0
- package/src/lightning/datatable/autoWidthStrategy.js +8 -36
- package/src/lightning/datatable/columnResizer.js +51 -161
- package/src/lightning/datatable/columnWidthManager.js +25 -81
- package/src/lightning/datatable/columns.js +180 -302
- package/src/lightning/datatable/datatable.js +454 -441
- package/src/lightning/datatable/errors.js +17 -29
- package/src/lightning/datatable/fixedWidthStrategy.js +7 -22
- package/src/lightning/datatable/headerActions.js +8 -38
- package/src/lightning/datatable/indexes.js +42 -0
- package/src/lightning/datatable/infiniteLoading.js +16 -35
- package/src/lightning/datatable/inlineEdit.js +126 -156
- package/src/lightning/datatable/keyboard.js +226 -282
- package/src/lightning/datatable/renderManager.js +0 -4
- package/src/lightning/datatable/resizeObserver.js +4 -13
- package/src/lightning/datatable/rowLevelActions.js +2 -2
- package/src/lightning/datatable/rowNumber.js +21 -59
- package/src/lightning/datatable/rowSelection.js +95 -178
- package/src/lightning/datatable/rowSelectionShared.js +13 -27
- package/src/lightning/datatable/rows.js +171 -418
- package/src/lightning/datatable/sort.js +16 -75
- package/src/lightning/datatable/templates/div/div.html +12 -4
- package/src/lightning/datatable/templates/div/div.lbc.synthetic.css +10 -16
- package/src/lightning/datatable/templates/table/table.html +15 -5
- package/src/lightning/datatable/tree.js +17 -35
- package/src/lightning/datatable/types.js +10 -31
- package/src/lightning/datatable/utils.js +48 -24
- package/src/lightning/datatable/virtualization.js +2 -5
- package/src/lightning/datatable/widthManagerShared.js +0 -20
- package/src/lightning/datatable/wrapText.js +29 -60
- package/src/lightning/dualListbox/__docs__/dualListbox.md +0 -4
- package/src/lightning/dualListbox/dualListbox.js +7 -8
- package/src/lightning/dynamicIcon/__docs__/dynamicIcon.md +0 -4
- package/src/lightning/formattedDateTime/__docs__/formattedDateTime.md +0 -4
- package/src/lightning/formattedLocation/__docs__/formattedLocation.md +0 -4
- package/src/lightning/formattedName/__docs__/formattedName.md +0 -4
- package/src/lightning/formattedName/formattedName.js +3 -2
- package/src/lightning/formattedName/formattedName.js-meta.xml +3 -0
- package/src/lightning/formattedNumber/__docs__/formattedNumber.md +0 -4
- package/src/lightning/formattedNumber/formattedNumber.js +3 -2
- package/src/lightning/formattedNumber/formattedNumber.js-meta.xml +3 -0
- package/src/lightning/formattedPhone/__docs__/formattedPhone.md +0 -4
- package/src/lightning/formattedRichText/richTextConfig.js +1 -0
- package/src/lightning/formattedText/__docs__/formattedText.md +0 -4
- package/src/lightning/formattedTime/__docs__/formattedTime.md +0 -4
- package/src/lightning/formattedUrl/__docs__/formattedUrl.md +0 -4
- package/src/lightning/helptext/helptext.css +7 -0
- package/src/lightning/helptext/helptext.js +3 -4
- package/src/lightning/icon/__docs__/icon.md +0 -4
- package/src/lightning/icon/icon.html +1 -1
- package/src/lightning/input/input.html +5 -0
- package/src/lightning/inputAddress/addressFormat.js +31 -4
- package/src/lightning/inputAddress/fieldsLayout.js +6 -0
- package/src/lightning/inputAddress/inputAddress.html +19 -1
- package/src/lightning/inputAddress/inputAddress.js +80 -3
- package/src/lightning/inputLocation/__docs__/inputLocation.md +0 -4
- package/src/lightning/internationalizationLibrary/address/AddressFormat.js +553 -610
- package/src/lightning/layout/__docs__/layout.md +0 -4
- package/src/lightning/layoutItem/__docs__/layoutItem.md +0 -4
- package/src/lightning/lookupAddress/lookupAddress.html +6 -1
- package/src/lightning/lookupAddress/lookupAddress.js +25 -0
- package/src/lightning/menuItem/__docs__/menuItem.md +0 -4
- package/src/lightning/menuSubheader/menu-subheader.slds.css +1 -1
- package/src/lightning/modal/__docs__/modal.md +10 -1
- package/src/lightning/modal/__modalUtils__/modalContainerTestConstants.js +3 -7
- package/src/lightning/modal/__modalUtils__/modalContainerTestMethods.js +39 -133
- package/src/lightning/modal/__modalUtils__/modalContainerTestMockData.js +1 -1
- package/src/lightning/modal/modal.js +1 -1
- package/src/lightning/modalBase/modalBase.html +15 -10
- package/src/lightning/modalBase/modalBase.js +132 -147
- package/src/lightning/modalBody/modalBody.css +6 -0
- package/src/lightning/modalHeader/modalHeader.html +16 -4
- package/src/lightning/modalHeader/modalHeader.js +61 -14
- package/src/lightning/pill/__docs__/pill.md +0 -4
- package/src/lightning/pill/link.html +1 -0
- package/src/lightning/pill/plain.html +1 -0
- package/src/lightning/pill/plainLink.html +1 -0
- package/src/lightning/pillContainer/__docs__/pillContainer.md +0 -4
- package/src/lightning/primitiveBubble/primitiveBubble.js +42 -0
- package/src/lightning/primitiveDatatableCell/primitiveDatatableCell.js +1 -1
- package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.html +1 -1
- package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.js +13 -0
- package/src/lightning/primitiveHeaderFactory/nonsortableHeader.html +19 -6
- package/src/lightning/primitiveHeaderFactory/sortableHeader.html +3 -1
- package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.css +11 -0
- package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.html +2 -1
- package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.js +1 -0
- package/src/lightning/progressStep/base.html +5 -6
- package/src/lightning/progressStep/progressStep.js +14 -9
- package/src/lightning/prompt/__docs__/prompt.md +1 -1
- package/src/lightning/radioGroup/__docs__/radioGroup.md +0 -4
- package/src/lightning/relativeDateTime/__docs__/relativeDateTime.md +0 -4
- package/src/lightning/shadowBaseClassPrivate/shadowBaseClassPrivate.js +0 -2
- package/src/lightning/sldsCommon/sldsCommon.css +134 -98
- package/src/lightning/sldsUtilsAlignment/sldsUtilsAlignment.css +1 -1
- package/src/lightning/sldsUtilsBox/sldsUtilsBox.css +14 -13
- package/src/lightning/sldsUtilsGrid/sldsUtilsGrid.css +95 -92
- package/src/lightning/sldsUtilsHyphenation/sldsUtilsHyphenation.css +1 -1
- package/src/lightning/sldsUtilsMargin/sldsUtilsMargin.css +77 -75
- package/src/lightning/sldsUtilsPadding/sldsUtilsPadding.css +73 -73
- package/src/lightning/sldsUtilsSizing/sldsUtilsSizing.css +552 -558
- package/src/lightning/sldsUtilsVisibility/sldsUtilsVisibility.css +2 -2
- package/src/lightning/slider/__docs__/slider.md +0 -4
- package/src/lightning/spinner/__docs__/spinner.md +0 -4
- package/src/lightning/staticMap/staticMap.js +3 -2
- package/src/lightning/tab/__docs__/tab.md +0 -4
- package/src/lightning/tab/tab.js +6 -3
- package/src/lightning/tab/tab.js-meta.xml +3 -0
- package/src/lightning/tabBar/tabBar.js +10 -5
- package/src/lightning/tabset/__docs__/tabset.md +0 -4
- package/src/lightning/tabset/tabset.html +2 -0
- package/src/lightning/tabset/tabset.js-meta.xml +3 -0
- package/src/lightning/textarea/__docs__/textarea.md +0 -4
- package/src/lightning/textarea/textarea.js +6 -1
- package/src/lightning/tile/__docs__/tile.md +0 -4
- package/src/lightning/toastContainer/__docs__/toastContainer.md +3 -2
- package/src/lightning/tooltipLibrary/tooltipLibrary.js +24 -15
- package/src/lightning/tree/__docs__/tree.md +0 -4
- package/src/lightning/tree/tree.js +5 -1
- package/src/lightning/verticalNavigation/__docs__/verticalNavigation.md +0 -4
- package/src/lightning/verticalNavigation/vertical-navigation.slds.css +14 -0
- package/src/lightning/verticalNavigation/verticalNavigation.css +1 -1
- package/src/lightning/verticalNavigation/verticalNavigation.html +1 -1
- package/src/lightning/verticalNavigation/verticalNavigation.js +66 -28
- package/src/lightning/verticalNavigation/verticalNavigation.js-meta.xml +3 -0
- package/src/lightning/verticalNavigationItem/__docs__/verticalNavigationItem.md +0 -4
- package/src/lightning/verticalNavigationItem/vertical-navigation-item.slds.css +63 -0
- package/src/lightning/verticalNavigationItem/verticalNavigationItem.css +2 -3
- package/src/lightning/verticalNavigationItem/verticalNavigationItem.js +29 -15
- package/src/lightning/verticalNavigationItem/verticalNavigationItem.js-meta.xml +3 -0
- package/src/lightning/verticalNavigationItem/verticalNavigationItem.lbc.native.css +2 -0
- package/src/lightning/verticalNavigationItem/verticalNavigationItem.lbc.synthetic.css +3 -0
- package/src/lightning/verticalNavigationItemBadge/__docs__/verticalNavigationItemBadge.md +0 -4
- package/src/lightning/verticalNavigationItemBadge/badge.slds.css +76 -0
- package/src/lightning/verticalNavigationItemBadge/vertical-navigation-item.slds.css +63 -0
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.css +2 -3
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.html +1 -1
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.js +28 -15
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.js-meta.xml +3 -0
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.lbc.native.css +5 -0
- package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.lbc.synthetic.css +3 -0
- package/src/lightning/verticalNavigationItemIcon/__docs__/verticalNavigationItemIcon.md +0 -4
- package/src/lightning/verticalNavigationItemIcon/vertical-navigation-item.slds.css +63 -0
- package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.css +2 -3
- package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.js +29 -15
- package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.js-meta.xml +3 -0
- package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.lbc.native.css +3 -0
- package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.lbc.synthetic.css +3 -0
- package/src/lightning/verticalNavigationOverflow/button.slds.css +503 -0
- package/src/lightning/verticalNavigationOverflow/vertical-navigation-item.slds.css +63 -0
- package/src/lightning/verticalNavigationOverflow/vertical-navigation-section.slds.css +17 -0
- package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.css +2 -1
- package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.html +2 -0
- package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.js +18 -13
- package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.js-meta.xml +3 -0
- package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.lbc.native.css +5 -0
- package/src/lightning/verticalNavigationSection/vertical-navigation-section.slds.css +14 -14
- package/src/lightning/verticalNavigationSection/verticalNavigationSection.js-meta.xml +3 -0
- package/src/lightning/datatable/inlineEditShared.js +0 -26
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatableWrapper/customDatatableWrapper.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatableWrapper/customDatatableWrapper.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeLink/customDatatypeLink.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeLink/customDatatypeLink.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeNumber/customDatatypeNumber.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeNumber/customDatatypeNumber.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customDatatypeTable.js +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customLink.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customName.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customNumber.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customNumberEdit.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/deleteRow.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/iconPill.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/orderingButtons.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customNestedComponent/customNestedComponent.html +0 -0
- /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customNestedComponent/customNestedComponent.js +0 -0
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
generateColKeyValue,
|
|
4
|
-
getStateColumnIndex,
|
|
5
|
-
} from './columns';
|
|
1
|
+
import { getShadowActiveElements, isRTL } from 'lightning/utilsPrivate';
|
|
2
|
+
import { getCellFromIndexes, HEADER_ROW_KEY, getRowByKey } from './indexes';
|
|
6
3
|
import {
|
|
7
4
|
hasTreeDataType,
|
|
8
5
|
getStateTreeColumn,
|
|
9
6
|
fireRowToggleEvent,
|
|
10
7
|
} from './tree';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { generateColKeyValue, getStateColumnIndex } from './columns';
|
|
9
|
+
import { isCellEditable } from './rows';
|
|
13
10
|
import { findFirstVisibleIndex } from './virtualization';
|
|
14
|
-
|
|
15
|
-
import { escapeDoubleQuotes } from './utils';
|
|
16
|
-
|
|
17
|
-
// Indicator/flag for a header row
|
|
18
|
-
const HEADER_ROW = 'HEADER';
|
|
11
|
+
import { getColDataSelector, getRowDataSelector, getScrollerY } from './utils';
|
|
19
12
|
|
|
20
13
|
// SLDS Class for Focus
|
|
21
14
|
export const FOCUS_CLASS = 'slds-has-focus';
|
|
22
15
|
|
|
23
16
|
// Keyboard Navigation Modes
|
|
24
|
-
const
|
|
25
|
-
const
|
|
17
|
+
export const KEYBOARD_NAVIGATION_MODE = 'NAVIGATION';
|
|
18
|
+
export const KEYBOARD_ACTION_MODE = 'ACTION';
|
|
26
19
|
|
|
27
20
|
// Pixel Values
|
|
28
21
|
const TOP_MARGIN = 80;
|
|
@@ -40,7 +33,7 @@ const TAB = 9;
|
|
|
40
33
|
const SPACE = 32;
|
|
41
34
|
|
|
42
35
|
// Navigation Direction
|
|
43
|
-
const NAVIGATION_DIR = isRTL()
|
|
36
|
+
export const NAVIGATION_DIR = isRTL()
|
|
44
37
|
? {
|
|
45
38
|
RIGHT: -1,
|
|
46
39
|
LEFT: 1,
|
|
@@ -58,22 +51,6 @@ const NAVIGATION_DIR = isRTL()
|
|
|
58
51
|
TAB_BACKWARD: -1,
|
|
59
52
|
};
|
|
60
53
|
|
|
61
|
-
// Selectors
|
|
62
|
-
const SELECTORS = {
|
|
63
|
-
headerRow: {
|
|
64
|
-
default: `thead > :nth-child(1)`,
|
|
65
|
-
roleBased: `[role="grid"] > [role="rowgroup"]:nth-child(1) > [role="row"]`,
|
|
66
|
-
},
|
|
67
|
-
dataRowRowGroup: {
|
|
68
|
-
default: `tbody`,
|
|
69
|
-
roleBased: `[role="grid"] > [role="rowgroup"]:nth-child(2)`,
|
|
70
|
-
},
|
|
71
|
-
cell: {
|
|
72
|
-
default: ['td', 'th'],
|
|
73
|
-
roleBased: ['rowheader', 'gridcell', 'columnheader'],
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
54
|
/***************************** KEYDOWN HANDLERS *****************************/
|
|
78
55
|
|
|
79
56
|
/**
|
|
@@ -90,7 +67,7 @@ const SELECTORS = {
|
|
|
90
67
|
*/
|
|
91
68
|
export function handleKeydownOnCell(event) {
|
|
92
69
|
event.stopPropagation();
|
|
93
|
-
reactToKeyboardInActionMode(this
|
|
70
|
+
reactToKeyboardInActionMode(this, event);
|
|
94
71
|
}
|
|
95
72
|
|
|
96
73
|
/**
|
|
@@ -111,13 +88,10 @@ export function handleKeydownOnCell(event) {
|
|
|
111
88
|
* @param {Event} event
|
|
112
89
|
*/
|
|
113
90
|
export function handleKeydownOnTable(event) {
|
|
114
|
-
const targetTagName = event.target.tagName.toLowerCase();
|
|
115
|
-
const targetRole = event.target.getAttribute('role');
|
|
116
|
-
|
|
117
91
|
// Checks if the keydown happened on a cell element and not
|
|
118
92
|
// on an actionable element when in Action Mode.
|
|
119
|
-
if (isCellElement(
|
|
120
|
-
reactToKeyboardInNavMode(this
|
|
93
|
+
if (isCellElement(event.target)) {
|
|
94
|
+
reactToKeyboardInNavMode(this, event);
|
|
121
95
|
}
|
|
122
96
|
}
|
|
123
97
|
|
|
@@ -125,51 +99,52 @@ export function handleKeydownOnTable(event) {
|
|
|
125
99
|
* Changes the datatable state based on the keyboard event sent from the cell component.
|
|
126
100
|
* The result of those changes may trigger a re-render on the table
|
|
127
101
|
*
|
|
128
|
-
* @param {
|
|
129
|
-
* @param {Object} state Datatable state
|
|
102
|
+
* @param {Object} dt - The datatable instance
|
|
130
103
|
* @param {Event} event Custom DOM event sent by the cell
|
|
131
104
|
* @returns {Object} Mutated state
|
|
132
105
|
*/
|
|
133
|
-
function reactToKeyboardInActionMode(
|
|
106
|
+
function reactToKeyboardInActionMode(dt, event) {
|
|
107
|
+
const { state, template } = dt;
|
|
134
108
|
switch (event.detail.keyCode) {
|
|
135
109
|
case ARROW_LEFT:
|
|
136
|
-
reactToArrowLeft(
|
|
110
|
+
reactToArrowLeft(state, template, event);
|
|
137
111
|
break;
|
|
138
112
|
case ARROW_RIGHT:
|
|
139
|
-
reactToArrowRight(
|
|
113
|
+
reactToArrowRight(state, template, event);
|
|
140
114
|
break;
|
|
141
115
|
case ARROW_UP:
|
|
142
|
-
reactToArrowUp(
|
|
116
|
+
reactToArrowUp(state, template, event);
|
|
143
117
|
break;
|
|
144
118
|
case ARROW_DOWN:
|
|
145
|
-
reactToArrowDown(
|
|
119
|
+
reactToArrowDown(state, template, event);
|
|
146
120
|
break;
|
|
147
121
|
case ENTER:
|
|
148
122
|
case SPACE:
|
|
149
|
-
reactToEnter(
|
|
123
|
+
reactToEnter(state, template, event);
|
|
150
124
|
break;
|
|
151
125
|
case ESCAPE:
|
|
152
|
-
reactToEscape(
|
|
126
|
+
reactToEscape(state, template, event);
|
|
153
127
|
break;
|
|
154
128
|
case TAB:
|
|
155
|
-
reactToTab(
|
|
129
|
+
reactToTab(state, template, event);
|
|
156
130
|
break;
|
|
157
131
|
default:
|
|
158
132
|
break;
|
|
159
133
|
}
|
|
160
134
|
}
|
|
161
135
|
|
|
162
|
-
function reactToKeyboardInNavMode(
|
|
136
|
+
function reactToKeyboardInNavMode(dt, event) {
|
|
137
|
+
const { state, template } = dt;
|
|
163
138
|
const {
|
|
164
139
|
activeCell: { colKeyValue, rowKeyValue },
|
|
165
140
|
} = state;
|
|
166
141
|
const { keyCode, shiftKey } = event;
|
|
167
142
|
const syntheticEvent = {
|
|
168
143
|
detail: {
|
|
169
|
-
rowKeyValue,
|
|
170
144
|
colKeyValue,
|
|
171
|
-
|
|
172
|
-
|
|
145
|
+
rowKeyValue,
|
|
146
|
+
keyCode,
|
|
147
|
+
shiftKey,
|
|
173
148
|
},
|
|
174
149
|
preventDefault: () => {},
|
|
175
150
|
stopPropagation: () => {},
|
|
@@ -179,59 +154,59 @@ function reactToKeyboardInNavMode(element, state, event) {
|
|
|
179
154
|
switch (event.keyCode) {
|
|
180
155
|
case ARROW_LEFT:
|
|
181
156
|
event.preventDefault();
|
|
182
|
-
reactToArrowLeft(
|
|
157
|
+
reactToArrowLeft(state, template, syntheticEvent);
|
|
183
158
|
break;
|
|
184
159
|
case ARROW_RIGHT:
|
|
185
160
|
event.preventDefault();
|
|
186
|
-
reactToArrowRight(
|
|
161
|
+
reactToArrowRight(state, template, syntheticEvent);
|
|
187
162
|
break;
|
|
188
163
|
case ARROW_UP:
|
|
189
164
|
event.preventDefault();
|
|
190
|
-
reactToArrowUp(
|
|
165
|
+
reactToArrowUp(state, template, syntheticEvent);
|
|
191
166
|
break;
|
|
192
167
|
case ARROW_DOWN:
|
|
193
168
|
event.preventDefault();
|
|
194
|
-
reactToArrowDown(
|
|
169
|
+
reactToArrowDown(state, template, syntheticEvent);
|
|
195
170
|
break;
|
|
196
171
|
case ENTER:
|
|
197
172
|
case SPACE:
|
|
198
173
|
event.preventDefault();
|
|
199
|
-
reactToEnter(
|
|
174
|
+
reactToEnter(state, template, syntheticEvent);
|
|
200
175
|
break;
|
|
201
176
|
case ESCAPE:
|
|
202
177
|
// td, th or div[role=gridcell/rowheader] is the active element in the
|
|
203
178
|
// action mode if cell doesn't have action elements; hence this can be
|
|
204
179
|
// reached and we should react to escape as exiting from action mode
|
|
205
180
|
syntheticEvent.detail.keyEvent = event;
|
|
206
|
-
reactToEscape(
|
|
181
|
+
reactToEscape(state, template, syntheticEvent);
|
|
207
182
|
break;
|
|
208
183
|
case TAB:
|
|
209
|
-
reactToTab(
|
|
184
|
+
reactToTab(state, template, syntheticEvent);
|
|
210
185
|
break;
|
|
211
186
|
default:
|
|
212
187
|
break;
|
|
213
188
|
}
|
|
214
189
|
}
|
|
215
190
|
|
|
216
|
-
function
|
|
217
|
-
setBlurActiveCell(element, state);
|
|
218
|
-
setRowNavigationMode(state);
|
|
219
|
-
setFocusActiveRow(element, state);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function reactToArrowLeft(element, state, event) {
|
|
191
|
+
function reactToArrowLeft(state, template, event) {
|
|
223
192
|
const { rowKeyValue, colKeyValue } = event.detail;
|
|
224
193
|
const { colIndex } = getIndexesByKeys(state, rowKeyValue, colKeyValue);
|
|
225
194
|
// Move from navigation mode to row mode when user
|
|
226
195
|
// arrows left when in nav mode and on the first column
|
|
227
196
|
if (colIndex === 0 && canBeRowNavigationMode(state)) {
|
|
228
|
-
|
|
197
|
+
// Tracked state change.
|
|
198
|
+
// Move from cell to row.
|
|
199
|
+
setBlurActiveCell(state, template);
|
|
200
|
+
// Untracked state change.
|
|
201
|
+
setRowNavigationMode(state);
|
|
202
|
+
// Tracked state change.
|
|
203
|
+
setFocusActiveRow(state, template);
|
|
229
204
|
} else {
|
|
230
205
|
const nextColIndex = getNextIndexLeft(state, colIndex);
|
|
231
206
|
if (nextColIndex === undefined) {
|
|
232
207
|
return;
|
|
233
208
|
}
|
|
234
|
-
setBlurActiveCell(
|
|
209
|
+
setBlurActiveCell(state, template);
|
|
235
210
|
// Untracked state change.
|
|
236
211
|
// Update activeCell.
|
|
237
212
|
state.activeCell = {
|
|
@@ -242,18 +217,18 @@ function reactToArrowLeft(element, state, event) {
|
|
|
242
217
|
),
|
|
243
218
|
};
|
|
244
219
|
// Tracked state change.
|
|
245
|
-
setFocusActiveCell(
|
|
220
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.LEFT);
|
|
246
221
|
}
|
|
247
222
|
}
|
|
248
223
|
|
|
249
|
-
function reactToArrowRight(
|
|
224
|
+
function reactToArrowRight(state, template, event) {
|
|
250
225
|
const { rowKeyValue, colKeyValue } = event.detail;
|
|
251
226
|
const { colIndex } = getIndexesByKeys(state, rowKeyValue, colKeyValue);
|
|
252
227
|
const nextColIndex = getNextIndexRight(state, colIndex);
|
|
253
228
|
if (nextColIndex === undefined) {
|
|
254
229
|
return;
|
|
255
230
|
}
|
|
256
|
-
setBlurActiveCell(
|
|
231
|
+
setBlurActiveCell(state, template);
|
|
257
232
|
// Untracked state change.
|
|
258
233
|
// Update activeCell.
|
|
259
234
|
state.activeCell = {
|
|
@@ -263,10 +238,10 @@ function reactToArrowRight(element, state, event) {
|
|
|
263
238
|
nextColIndex
|
|
264
239
|
),
|
|
265
240
|
};
|
|
266
|
-
setFocusActiveCell(
|
|
241
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.RIGHT);
|
|
267
242
|
}
|
|
268
243
|
|
|
269
|
-
function reactToArrowUp(
|
|
244
|
+
function reactToArrowUp(state, template, event) {
|
|
270
245
|
const { rowKeyValue, colKeyValue, keyEvent } = event.detail;
|
|
271
246
|
const { rowIndex } = getIndexesByKeys(state, rowKeyValue, colKeyValue);
|
|
272
247
|
const nextRowIndex = getNextIndexUp(state, rowIndex);
|
|
@@ -281,18 +256,19 @@ function reactToArrowUp(element, state, event) {
|
|
|
281
256
|
keyEvent.stopPropagation();
|
|
282
257
|
}
|
|
283
258
|
// Tracked state change.
|
|
284
|
-
setBlurActiveCell(
|
|
259
|
+
setBlurActiveCell(state, template);
|
|
285
260
|
// Untracked state change.
|
|
286
261
|
// Update activeCell.
|
|
287
262
|
state.activeCell = {
|
|
288
263
|
rowKeyValue:
|
|
289
|
-
nextRowIndex
|
|
264
|
+
nextRowIndex === -1 ? HEADER_ROW_KEY : state.rows[nextRowIndex].key,
|
|
290
265
|
colKeyValue,
|
|
291
266
|
};
|
|
292
|
-
|
|
267
|
+
// Tracked state change.
|
|
268
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.USE_CURRENT);
|
|
293
269
|
}
|
|
294
270
|
|
|
295
|
-
function reactToArrowDown(
|
|
271
|
+
function reactToArrowDown(state, template, event) {
|
|
296
272
|
const { rowKeyValue, colKeyValue, keyEvent } = event.detail;
|
|
297
273
|
const { rowIndex } = getIndexesByKeys(state, rowKeyValue, colKeyValue);
|
|
298
274
|
const nextRowIndex = getNextIndexDown(state, rowIndex);
|
|
@@ -307,56 +283,52 @@ function reactToArrowDown(element, state, event) {
|
|
|
307
283
|
keyEvent.stopPropagation();
|
|
308
284
|
}
|
|
309
285
|
// Tracked state change.
|
|
310
|
-
setBlurActiveCell(
|
|
286
|
+
setBlurActiveCell(state, template);
|
|
311
287
|
// Untracked state change.
|
|
312
288
|
// Update activeCell.
|
|
313
289
|
state.activeCell = {
|
|
314
290
|
rowKeyValue:
|
|
315
|
-
nextRowIndex
|
|
291
|
+
nextRowIndex === -1 ? HEADER_ROW_KEY : state.rows[nextRowIndex].key,
|
|
316
292
|
colKeyValue,
|
|
317
293
|
};
|
|
318
|
-
setFocusActiveCell(
|
|
294
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.USE_CURRENT);
|
|
319
295
|
}
|
|
320
296
|
|
|
321
|
-
function reactToEnter(
|
|
322
|
-
if (state.keyboardMode ===
|
|
297
|
+
function reactToEnter(state, template, event) {
|
|
298
|
+
if (state.keyboardMode === KEYBOARD_NAVIGATION_MODE) {
|
|
323
299
|
// Untracked state change.
|
|
324
|
-
state.keyboardMode =
|
|
300
|
+
state.keyboardMode = KEYBOARD_ACTION_MODE;
|
|
325
301
|
const { keyCode, keyEvent } = event.detail;
|
|
326
302
|
const { rowIndex, colIndex } = getIndexesActiveCell(state);
|
|
327
303
|
if (keyEvent) {
|
|
328
304
|
keyEvent.preventDefault();
|
|
329
305
|
}
|
|
330
|
-
|
|
331
306
|
const info = { action: undefined };
|
|
332
307
|
if (keyCode === SPACE) {
|
|
333
308
|
info.action = 'space';
|
|
334
309
|
} else if (keyCode === ENTER) {
|
|
335
310
|
info.action = 'enter';
|
|
336
311
|
}
|
|
337
|
-
const actionsMap = {};
|
|
338
|
-
actionsMap[SPACE] = 'space';
|
|
339
|
-
actionsMap[ENTER] = 'enter';
|
|
340
312
|
// Tracked state changes.
|
|
341
|
-
setModeActiveCell(
|
|
313
|
+
setModeActiveCell(state, template, info);
|
|
342
314
|
updateCellTabIndex(state, rowIndex, colIndex, -1);
|
|
343
315
|
}
|
|
344
316
|
}
|
|
345
317
|
|
|
346
|
-
function reactToEscape(
|
|
347
|
-
if (state.keyboardMode ===
|
|
318
|
+
function reactToEscape(state, template, event) {
|
|
319
|
+
if (state.keyboardMode === KEYBOARD_ACTION_MODE) {
|
|
348
320
|
// When the table is in action mode this event shouldn't bubble
|
|
349
321
|
// because if the table in inside a modal it should prevent the modal closes
|
|
350
322
|
event.detail.keyEvent.stopPropagation();
|
|
351
323
|
// Untracked state change.
|
|
352
|
-
state.keyboardMode =
|
|
324
|
+
state.keyboardMode = KEYBOARD_NAVIGATION_MODE;
|
|
353
325
|
// Tracked state changes.
|
|
354
|
-
setModeActiveCell(
|
|
355
|
-
setFocusActiveCell(
|
|
326
|
+
setModeActiveCell(state, template);
|
|
327
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.RESET);
|
|
356
328
|
}
|
|
357
329
|
}
|
|
358
330
|
|
|
359
|
-
function reactToTab(
|
|
331
|
+
function reactToTab(state, template, event) {
|
|
360
332
|
event.preventDefault();
|
|
361
333
|
event.stopPropagation();
|
|
362
334
|
|
|
@@ -365,7 +337,7 @@ function reactToTab(element, state, event) {
|
|
|
365
337
|
const isExitCell = isActiveCellAnExitCell(state, direction);
|
|
366
338
|
|
|
367
339
|
// If in ACTION mode.
|
|
368
|
-
if (state.keyboardMode ===
|
|
340
|
+
if (state.keyboardMode === KEYBOARD_ACTION_MODE) {
|
|
369
341
|
// If not on last or first cell, tab through each cell of the grid.
|
|
370
342
|
if (isExitCell === false) {
|
|
371
343
|
// Prevent default key event in action mode when actually moving within the grid.
|
|
@@ -375,16 +347,16 @@ function reactToTab(element, state, event) {
|
|
|
375
347
|
}
|
|
376
348
|
// Tab in proper direction based on shift key press.
|
|
377
349
|
if (direction === 'BACKWARD') {
|
|
378
|
-
reactToTabBackward(
|
|
350
|
+
reactToTabBackward(state, template);
|
|
379
351
|
} else {
|
|
380
|
-
reactToTabForward(
|
|
352
|
+
reactToTabForward(state, template);
|
|
381
353
|
}
|
|
382
354
|
} else {
|
|
383
355
|
// Untracked state change.
|
|
384
356
|
// Exit ACTION mode.
|
|
385
|
-
state.keyboardMode =
|
|
357
|
+
state.keyboardMode = KEYBOARD_NAVIGATION_MODE;
|
|
386
358
|
// Tracked state change.
|
|
387
|
-
setModeActiveCell(
|
|
359
|
+
setModeActiveCell(state, template);
|
|
388
360
|
// Untracked state change.
|
|
389
361
|
state.isExitingActionMode = true;
|
|
390
362
|
}
|
|
@@ -394,41 +366,42 @@ function reactToTab(element, state, event) {
|
|
|
394
366
|
}
|
|
395
367
|
}
|
|
396
368
|
|
|
397
|
-
export function reactToTabForward(
|
|
369
|
+
export function reactToTabForward(state, template) {
|
|
398
370
|
const { nextColIndex, nextRowIndex } = getNextIndexOnTab(state, 'FORWARD');
|
|
399
371
|
// Tracked state change.
|
|
400
|
-
setBlurActiveCell(
|
|
372
|
+
setBlurActiveCell(state, template);
|
|
373
|
+
// Untracked state change.
|
|
401
374
|
// Update activeCell.
|
|
402
375
|
state.activeCell = {
|
|
403
376
|
rowKeyValue:
|
|
404
|
-
nextRowIndex === -1 ?
|
|
377
|
+
nextRowIndex === -1 ? HEADER_ROW_KEY : state.rows[nextRowIndex].key,
|
|
405
378
|
colKeyValue: generateColKeyValue(
|
|
406
379
|
state.columns[nextColIndex],
|
|
407
380
|
nextColIndex
|
|
408
381
|
),
|
|
409
382
|
};
|
|
410
383
|
// Tracked state change.
|
|
411
|
-
setFocusActiveCell(
|
|
384
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.TAB_FORWARD, {
|
|
412
385
|
action: 'tab',
|
|
413
386
|
});
|
|
414
387
|
}
|
|
415
388
|
|
|
416
|
-
export function reactToTabBackward(
|
|
389
|
+
export function reactToTabBackward(state, template) {
|
|
417
390
|
const { nextColIndex, nextRowIndex } = getNextIndexOnTab(state, 'BACKWARD');
|
|
418
391
|
// Tracked state change.
|
|
419
|
-
setBlurActiveCell(
|
|
392
|
+
setBlurActiveCell(state, template);
|
|
420
393
|
// Untracked state change.
|
|
421
394
|
// Update activeCell.
|
|
422
395
|
state.activeCell = {
|
|
423
396
|
rowKeyValue:
|
|
424
|
-
nextRowIndex === -1 ?
|
|
397
|
+
nextRowIndex === -1 ? HEADER_ROW_KEY : state.rows[nextRowIndex].key,
|
|
425
398
|
colKeyValue: generateColKeyValue(
|
|
426
399
|
state.columns[nextColIndex],
|
|
427
400
|
nextColIndex
|
|
428
401
|
),
|
|
429
402
|
};
|
|
430
403
|
// Tracked state change.
|
|
431
|
-
setFocusActiveCell(
|
|
404
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.TAB_BACKWARD, {
|
|
432
405
|
action: 'tab',
|
|
433
406
|
});
|
|
434
407
|
}
|
|
@@ -439,9 +412,9 @@ function getTabDirection(shiftKey) {
|
|
|
439
412
|
|
|
440
413
|
/**
|
|
441
414
|
* Retrieve the next index values for row & column when tab is pressed
|
|
442
|
-
* @param {
|
|
443
|
-
* @param {
|
|
444
|
-
* @returns {
|
|
415
|
+
* @param {Object} state - datatable state
|
|
416
|
+
* @param {String} direction - 'FORWARD' or 'BACKWARD'
|
|
417
|
+
* @returns {Object} - nextRowIndex, nextColIndex values, isExitCell boolean
|
|
445
418
|
*/
|
|
446
419
|
function getNextIndexOnTab(state, direction = 'FORWARD') {
|
|
447
420
|
const { rowIndex, colIndex } = getIndexesActiveCell(state);
|
|
@@ -493,12 +466,12 @@ function getNextIndexOnTabBackward(state, rowIndex, colIndex) {
|
|
|
493
466
|
* and will remove the user from row mode and place them in navigation mode
|
|
494
467
|
* Arrow Left: If cell is expanded, this will collapse the expanded row
|
|
495
468
|
*
|
|
496
|
-
* @param {
|
|
497
|
-
* @param {
|
|
498
|
-
* @param {*} event - The keydown event
|
|
469
|
+
* @param {Object} dt - The datatable instance
|
|
470
|
+
* @param {Object} event - The keydown event
|
|
499
471
|
* @returns Mutated state
|
|
500
472
|
*/
|
|
501
|
-
export function reactToKeyboardOnRow(dt,
|
|
473
|
+
export function reactToKeyboardOnRow(dt, event) {
|
|
474
|
+
const { state, template } = dt;
|
|
502
475
|
// TODO: Adapt this selector to also work in a role-based table once tree-grid is also migrated
|
|
503
476
|
const { localName } = event.target;
|
|
504
477
|
if (
|
|
@@ -506,19 +479,18 @@ export function reactToKeyboardOnRow(dt, state, event) {
|
|
|
506
479
|
localName.indexOf('tr') !== -1 &&
|
|
507
480
|
isRowNavigationMode(state)
|
|
508
481
|
) {
|
|
509
|
-
const element = dt.template;
|
|
510
482
|
switch (event.detail.keyCode) {
|
|
511
483
|
case ARROW_LEFT:
|
|
512
|
-
reactToArrowLeftOnRow
|
|
484
|
+
reactToArrowLeftOnRow(dt, state, template, event);
|
|
513
485
|
break;
|
|
514
486
|
case ARROW_RIGHT:
|
|
515
|
-
reactToArrowRightOnRow
|
|
487
|
+
reactToArrowRightOnRow(dt, state, template, event);
|
|
516
488
|
break;
|
|
517
489
|
case ARROW_UP:
|
|
518
|
-
reactToArrowUpOnRow
|
|
490
|
+
reactToArrowUpOnRow(dt, state, template, event);
|
|
519
491
|
break;
|
|
520
492
|
case ARROW_DOWN:
|
|
521
|
-
reactToArrowDownOnRow
|
|
493
|
+
reactToArrowDownOnRow(dt, state, template, event);
|
|
522
494
|
break;
|
|
523
495
|
default:
|
|
524
496
|
break;
|
|
@@ -526,12 +498,12 @@ export function reactToKeyboardOnRow(dt, state, event) {
|
|
|
526
498
|
}
|
|
527
499
|
}
|
|
528
500
|
|
|
529
|
-
function reactToArrowLeftOnRow(
|
|
501
|
+
function reactToArrowLeftOnRow(dt, state, template, event) {
|
|
530
502
|
const { rowKeyValue, rowHasChildren, rowExpanded, rowLevel } = event.detail;
|
|
531
503
|
// Check if row needs to be collapsed.
|
|
532
504
|
// If not, go to parent and focus there.
|
|
533
505
|
if (rowHasChildren && rowExpanded) {
|
|
534
|
-
fireRowToggleEvent
|
|
506
|
+
fireRowToggleEvent(dt, rowKeyValue, rowExpanded);
|
|
535
507
|
} else if (rowLevel > 1) {
|
|
536
508
|
const treeColumn = getStateTreeColumn(state);
|
|
537
509
|
if (treeColumn) {
|
|
@@ -544,7 +516,7 @@ function reactToArrowLeftOnRow(element, state, event) {
|
|
|
544
516
|
const parentIndex = getRowParentIndex(state, rowLevel, rowIndex);
|
|
545
517
|
if (parentIndex !== -1) {
|
|
546
518
|
// Tracked state change.
|
|
547
|
-
setBlurActiveRow(
|
|
519
|
+
setBlurActiveRow(state, template);
|
|
548
520
|
// Untracked state change.
|
|
549
521
|
// Update activeCell for the row.
|
|
550
522
|
state.activeCell = {
|
|
@@ -552,36 +524,33 @@ function reactToArrowLeftOnRow(element, state, event) {
|
|
|
552
524
|
colKeyValue,
|
|
553
525
|
};
|
|
554
526
|
// Tracked state change.
|
|
555
|
-
setFocusActiveRow(
|
|
527
|
+
setFocusActiveRow(state, template);
|
|
556
528
|
}
|
|
557
529
|
}
|
|
558
530
|
}
|
|
559
531
|
}
|
|
560
532
|
|
|
561
|
-
function
|
|
562
|
-
// Tracked state change.
|
|
563
|
-
setBlurActiveRow(element, state);
|
|
564
|
-
// Untracked state change.
|
|
565
|
-
unsetRowNavigationMode(state);
|
|
566
|
-
// Tracked state change.
|
|
567
|
-
setFocusActiveCell(element, state, NAVIGATION_DIR.USE_CURRENT);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function reactToArrowRightOnRow(element, state, event) {
|
|
533
|
+
function reactToArrowRightOnRow(dt, state, template, event) {
|
|
571
534
|
const { rowKeyValue, rowHasChildren, rowExpanded } = event.detail;
|
|
572
535
|
// Check if row needs to be expanded.
|
|
573
536
|
// Expand row if has children and is collapsed.
|
|
574
537
|
// Otherwise, make this.state.rowMode = false.
|
|
575
|
-
// Move
|
|
538
|
+
// Move tabIndex 0 to first cell in the row and focus there.
|
|
576
539
|
if (rowHasChildren && !rowExpanded) {
|
|
577
|
-
fireRowToggleEvent
|
|
540
|
+
fireRowToggleEvent(dt, rowKeyValue, rowExpanded);
|
|
578
541
|
} else {
|
|
579
|
-
|
|
542
|
+
// Tracked state change.
|
|
543
|
+
// Move from row to cell.
|
|
544
|
+
setBlurActiveRow(state, template);
|
|
545
|
+
// Untracked state change.
|
|
546
|
+
unsetRowNavigationMode(state);
|
|
547
|
+
// Tracked state change.
|
|
548
|
+
setFocusActiveCell(state, template, NAVIGATION_DIR.USE_CURRENT);
|
|
580
549
|
}
|
|
581
550
|
}
|
|
582
551
|
|
|
583
|
-
function reactToArrowUpOnRow(
|
|
584
|
-
// Move
|
|
552
|
+
function reactToArrowUpOnRow(state, template, event) {
|
|
553
|
+
// Move tabIndex 0 one row down.
|
|
585
554
|
const { rowKeyValue, keyEvent } = event.detail;
|
|
586
555
|
const treeColumn = getStateTreeColumn(state);
|
|
587
556
|
|
|
@@ -594,7 +563,7 @@ function reactToArrowUpOnRow(element, state, event) {
|
|
|
594
563
|
const prevRowIndex = getNextIndexUpWrapped(state, rowIndex);
|
|
595
564
|
if (prevRowIndex !== -1) {
|
|
596
565
|
// Tracked state change.
|
|
597
|
-
setBlurActiveRow(
|
|
566
|
+
setBlurActiveRow(state, template);
|
|
598
567
|
// Untracked state change.
|
|
599
568
|
// Update activeCell for the row.
|
|
600
569
|
state.activeCell = {
|
|
@@ -602,13 +571,13 @@ function reactToArrowUpOnRow(element, state, event) {
|
|
|
602
571
|
colKeyValue,
|
|
603
572
|
};
|
|
604
573
|
// Tracked state change.
|
|
605
|
-
setFocusActiveRow(
|
|
574
|
+
setFocusActiveRow(state, template);
|
|
606
575
|
}
|
|
607
576
|
}
|
|
608
577
|
}
|
|
609
578
|
|
|
610
|
-
function reactToArrowDownOnRow(
|
|
611
|
-
// Move
|
|
579
|
+
function reactToArrowDownOnRow(state, template, event) {
|
|
580
|
+
// Move tabIndex 0 one row down.
|
|
612
581
|
const { rowKeyValue, keyEvent } = event.detail;
|
|
613
582
|
const treeColumn = getStateTreeColumn(state);
|
|
614
583
|
|
|
@@ -621,15 +590,15 @@ function reactToArrowDownOnRow(element, state, event) {
|
|
|
621
590
|
const nextRowIndex = getNextIndexDownWrapped(state, rowIndex);
|
|
622
591
|
if (nextRowIndex !== -1) {
|
|
623
592
|
// Tracked state change.
|
|
624
|
-
setBlurActiveRow(
|
|
593
|
+
setBlurActiveRow(state, template);
|
|
625
594
|
// Untracked state change.
|
|
626
|
-
//
|
|
595
|
+
// Update activeCell for the row.
|
|
627
596
|
state.activeCell = {
|
|
628
597
|
rowKeyValue: state.rows[nextRowIndex].key,
|
|
629
598
|
colKeyValue,
|
|
630
599
|
};
|
|
631
600
|
// Tracked state change.
|
|
632
|
-
setFocusActiveRow(
|
|
601
|
+
setFocusActiveRow(state, template);
|
|
633
602
|
}
|
|
634
603
|
}
|
|
635
604
|
}
|
|
@@ -644,7 +613,7 @@ function getDefaultActiveCell(state) {
|
|
|
644
613
|
let existCustomerColumn = false;
|
|
645
614
|
for (let i = 0; i < colCount; i += 1) {
|
|
646
615
|
colIndex = i;
|
|
647
|
-
if (
|
|
616
|
+
if (columns[i].internal !== true) {
|
|
648
617
|
existCustomerColumn = true;
|
|
649
618
|
break;
|
|
650
619
|
}
|
|
@@ -654,7 +623,7 @@ function getDefaultActiveCell(state) {
|
|
|
654
623
|
}
|
|
655
624
|
const { rows } = state;
|
|
656
625
|
return {
|
|
657
|
-
rowKeyValue: rows.length > 0 ? rows[0].key :
|
|
626
|
+
rowKeyValue: rows.length > 0 ? rows[0].key : HEADER_ROW_KEY,
|
|
658
627
|
colKeyValue: generateColKeyValue(columns[colIndex], colIndex),
|
|
659
628
|
};
|
|
660
629
|
}
|
|
@@ -670,8 +639,8 @@ function setDefaultActiveCell(state) {
|
|
|
670
639
|
* Given a datatable template and state, returns an LWC component reference that represents
|
|
671
640
|
* the currently active cell in the table.
|
|
672
641
|
*
|
|
673
|
-
* @param {Object} template -
|
|
674
|
-
* @param {Object} state -
|
|
642
|
+
* @param {Object} template - The datatable template
|
|
643
|
+
* @param {Object} state - The datatable state
|
|
675
644
|
*/
|
|
676
645
|
export function getActiveCellElement(template, state) {
|
|
677
646
|
const { activeCell } = state;
|
|
@@ -687,10 +656,10 @@ export function getActiveCellElement(template, state) {
|
|
|
687
656
|
/**
|
|
688
657
|
* Returns if the pair rowKeyValue, colKeyValue are the current activeCell values
|
|
689
658
|
*
|
|
690
|
-
* @param {
|
|
691
|
-
* @param {
|
|
692
|
-
* @param {
|
|
693
|
-
* @returns {
|
|
659
|
+
* @param {Object} state - datatable state
|
|
660
|
+
* @param {String} rowKeyValue - the unique row key value
|
|
661
|
+
* @param {String} colKeyValue {string} - the unique col key value
|
|
662
|
+
* @returns {Boolean} - true if rowKeyValue, colKeyValue are the current activeCell values.
|
|
694
663
|
*/
|
|
695
664
|
export function isActiveCell(state, rowKeyValue, colKeyValue) {
|
|
696
665
|
const { activeCell } = state;
|
|
@@ -707,28 +676,13 @@ export function isActiveCell(state, rowKeyValue, colKeyValue) {
|
|
|
707
676
|
return false;
|
|
708
677
|
}
|
|
709
678
|
|
|
710
|
-
/**
|
|
711
|
-
* Updates the current activeCell in the state with the new rowKeyValue, colKeyValue
|
|
712
|
-
* @param {object} state - datatable state
|
|
713
|
-
* @param {string} rowKeyValue - the unique row key value
|
|
714
|
-
* @param {string} colKeyValue {string} - the unique col key value
|
|
715
|
-
* @returns {object} state - mutated datatable state
|
|
716
|
-
*/
|
|
717
|
-
export function updateActiveCell(state, rowKeyValue, colKeyValue) {
|
|
718
|
-
state.activeCell = {
|
|
719
|
-
rowKeyValue,
|
|
720
|
-
colKeyValue,
|
|
721
|
-
};
|
|
722
|
-
return state;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
679
|
/**
|
|
726
680
|
* It check if in the current (data, columns) the activeCell still valid.
|
|
727
681
|
* When data changed the activeCell could be removed, then we check if there is cellToFocusNext
|
|
728
682
|
* which is calculated from previously focused cell, if so we sync to that
|
|
729
683
|
* If active cell is still valid we keep it the same
|
|
730
684
|
*
|
|
731
|
-
* @param {
|
|
685
|
+
* @param {Object} state - The datatable state
|
|
732
686
|
*/
|
|
733
687
|
export function syncActiveCell(state) {
|
|
734
688
|
const { activeCell } = state;
|
|
@@ -758,7 +712,6 @@ function setNextActiveCellFromPrev(state) {
|
|
|
758
712
|
const { columns, rows } = state;
|
|
759
713
|
const { length: rowCount } = rows;
|
|
760
714
|
let nextRowIndex = rowIndex;
|
|
761
|
-
|
|
762
715
|
if (nextRowIndex > rowCount - 1) {
|
|
763
716
|
// row index not existing after update to new 5 > 5-1, 6 > 5-1,
|
|
764
717
|
nextRowIndex = rowCount - 1;
|
|
@@ -780,14 +733,14 @@ function setNextActiveCellFromPrev(state) {
|
|
|
780
733
|
} else {
|
|
781
734
|
setDefaultActiveCell(state);
|
|
782
735
|
}
|
|
783
|
-
state.keyboardMode =
|
|
736
|
+
state.keyboardMode = KEYBOARD_NAVIGATION_MODE;
|
|
784
737
|
}
|
|
785
738
|
|
|
786
739
|
/**
|
|
787
740
|
* Check if we're in an escape/exit cell (first or last of grid)
|
|
788
|
-
* @param {
|
|
789
|
-
* @param {
|
|
790
|
-
* @returns {
|
|
741
|
+
* @param {Object} state - The datatable state
|
|
742
|
+
* @param {String} direction - 'FORWARD' or 'BACKWARD'
|
|
743
|
+
* @returns {Boolean} - if the current cell is or isn't an exit cell
|
|
791
744
|
*/
|
|
792
745
|
export function isActiveCellAnExitCell(state, direction) {
|
|
793
746
|
// get next tab index values
|
|
@@ -816,8 +769,8 @@ export function getIndexesActiveCell(state) {
|
|
|
816
769
|
return getIndexesByKeys(state, rowKeyValue, colKeyValue);
|
|
817
770
|
}
|
|
818
771
|
|
|
819
|
-
function setModeActiveCell(
|
|
820
|
-
const cellElement = getActiveCellElement(
|
|
772
|
+
function setModeActiveCell(state, template, info) {
|
|
773
|
+
const cellElement = getActiveCellElement(template, state);
|
|
821
774
|
if (cellElement) {
|
|
822
775
|
cellElement.setMode(state.keyboardMode, info);
|
|
823
776
|
}
|
|
@@ -826,7 +779,7 @@ function setModeActiveCell(element, state, info) {
|
|
|
826
779
|
function stillValidActiveCell(state) {
|
|
827
780
|
const { activeCell, indexes } = state;
|
|
828
781
|
const { rowKeyValue, colKeyValue } = activeCell;
|
|
829
|
-
if (rowKeyValue ===
|
|
782
|
+
if (rowKeyValue === HEADER_ROW_KEY) {
|
|
830
783
|
if (state.rows.length) {
|
|
831
784
|
const { columns } = state;
|
|
832
785
|
let sortable = false;
|
|
@@ -849,18 +802,18 @@ function stillValidActiveCell(state) {
|
|
|
849
802
|
|
|
850
803
|
/**
|
|
851
804
|
* It set the focus to the current activeCell, this operation imply multiple changes
|
|
852
|
-
* - update the
|
|
805
|
+
* - update the tabIndex of the activeCell
|
|
853
806
|
* - set the current keyboard mode
|
|
854
807
|
* - set the focus to the cell
|
|
855
|
-
* @param {
|
|
856
|
-
* @param {
|
|
857
|
-
* @param {
|
|
858
|
-
* @param {
|
|
859
|
-
* @param {
|
|
808
|
+
* @param {Object} state - The datatable state
|
|
809
|
+
* @param {Node} template - The custom element template `this.template`
|
|
810
|
+
* @param {Integer} direction - The direction (-1 left, 1 right and 0 for no direction) its used to know which actionable element to activate.
|
|
811
|
+
* @param {Object} info - Extra information when setting the cell mode; currently only set when pressing tab
|
|
812
|
+
* @param {Boolean} [shouldScroll = true] - Whether scrollTop should be adjusted when setting focus
|
|
860
813
|
*/
|
|
861
814
|
export function setFocusActiveCell(
|
|
862
|
-
template,
|
|
863
815
|
state,
|
|
816
|
+
template,
|
|
864
817
|
direction,
|
|
865
818
|
info,
|
|
866
819
|
shouldScroll = true
|
|
@@ -914,15 +867,15 @@ export function setFocusActiveCell(
|
|
|
914
867
|
/**
|
|
915
868
|
* It blur to the current activeCell, this operation imply multiple changes
|
|
916
869
|
* - blur the activeCell
|
|
917
|
-
* - update the
|
|
918
|
-
* @param {
|
|
919
|
-
* @param {
|
|
870
|
+
* - update the tabIndex to -1
|
|
871
|
+
* @param {Object} state - The datatable state
|
|
872
|
+
* @param {Node} template - The custom element root `this.template`
|
|
920
873
|
*/
|
|
921
|
-
export function setBlurActiveCell(
|
|
874
|
+
export function setBlurActiveCell(state, template) {
|
|
922
875
|
if (state.activeCell) {
|
|
923
876
|
const { rowIndex, colIndex } = getIndexesActiveCell(state);
|
|
924
|
-
let cellElement = getActiveCellElement(template, state);
|
|
925
877
|
state.activeCell.focused = false;
|
|
878
|
+
let cellElement = getActiveCellElement(template, state);
|
|
926
879
|
// eslint-disable-next-line @lwc/lwc/no-async-operation
|
|
927
880
|
setTimeout(() => {
|
|
928
881
|
// check cellElement; value may have changed
|
|
@@ -955,15 +908,14 @@ export function setBlurActiveCell(template, state) {
|
|
|
955
908
|
* there is state.indexes
|
|
956
909
|
* there is no previously set state.cellToFocusNext
|
|
957
910
|
* Indexes are calculated as to what to focus on next
|
|
958
|
-
* @param {
|
|
959
|
-
* @param {
|
|
911
|
+
* @param {Object} state - The datatable state
|
|
912
|
+
* @param {Object} template - The datatable element
|
|
960
913
|
*/
|
|
961
914
|
export function setCellToFocusFromPrev(state, template) {
|
|
962
915
|
if (
|
|
963
916
|
state.activeCell &&
|
|
964
|
-
|
|
965
|
-
state
|
|
966
|
-
!state.cellToFocusNext
|
|
917
|
+
!state.cellToFocusNext &&
|
|
918
|
+
datatableHasFocus(state, template)
|
|
967
919
|
) {
|
|
968
920
|
const { length: rowCount } = state.rows;
|
|
969
921
|
const lastIndex = rowCount - 1;
|
|
@@ -985,7 +937,7 @@ export function setCellToFocusFromPrev(state, template) {
|
|
|
985
937
|
|
|
986
938
|
/**
|
|
987
939
|
* If the current new active still is valid (exists) then set the celltofocusnext to null.
|
|
988
|
-
* @param {
|
|
940
|
+
* @param {Object} state - The datatable state
|
|
989
941
|
*/
|
|
990
942
|
export function updateCellToFocusFromPrev(state) {
|
|
991
943
|
if (
|
|
@@ -998,21 +950,13 @@ export function updateCellToFocusFromPrev(state) {
|
|
|
998
950
|
}
|
|
999
951
|
}
|
|
1000
952
|
|
|
1001
|
-
/**
|
|
1002
|
-
* reset celltofocusnext to null (used after render)
|
|
1003
|
-
* @param {object} state - datatable state
|
|
1004
|
-
*/
|
|
1005
|
-
export function resetCellToFocusFromPrev(state) {
|
|
1006
|
-
state.cellToFocusNext = null;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
953
|
/**
|
|
1010
954
|
* It adds and the focus classes to the th/td or div[role=gridcell/rowheader].
|
|
1011
955
|
*
|
|
1012
|
-
* @param {
|
|
1013
|
-
* @param {
|
|
956
|
+
* @param {Object} state - The datatable state
|
|
957
|
+
* @param {Node} template - The custom element template `this.template`
|
|
1014
958
|
*/
|
|
1015
|
-
export function addFocusStylesToActiveCell(
|
|
959
|
+
export function addFocusStylesToActiveCell(state, template) {
|
|
1016
960
|
state.activeCell.focused = true;
|
|
1017
961
|
const cellElement = getActiveCellElement(template, state);
|
|
1018
962
|
if (cellElement) {
|
|
@@ -1022,13 +966,14 @@ export function addFocusStylesToActiveCell(template, state) {
|
|
|
1022
966
|
|
|
1023
967
|
/**
|
|
1024
968
|
* It set the focus to the row of current activeCell, this operation implies multiple changes
|
|
1025
|
-
* - update the
|
|
969
|
+
* - update the tabIndex of the activeCell
|
|
1026
970
|
* - set the current keyboard mode
|
|
1027
971
|
* - set the focus to the row
|
|
1028
|
-
*
|
|
1029
|
-
* @param {
|
|
972
|
+
*
|
|
973
|
+
* @param {Object} state - The datatable state
|
|
974
|
+
* @param {Node} template - the custom element root `this.template`
|
|
1030
975
|
*/
|
|
1031
|
-
function setFocusActiveRow(
|
|
976
|
+
function setFocusActiveRow(state, template) {
|
|
1032
977
|
const { rowIndex } = getIndexesActiveCell(state);
|
|
1033
978
|
const rowElement = getActiveCellRowElement(template, state);
|
|
1034
979
|
|
|
@@ -1043,18 +988,18 @@ function setFocusActiveRow(template, state) {
|
|
|
1043
988
|
/**
|
|
1044
989
|
* It blurs the active row, this operation implies multiple changes
|
|
1045
990
|
* - blur the active row
|
|
1046
|
-
* - update the
|
|
1047
|
-
* @param {
|
|
1048
|
-
* @param {
|
|
991
|
+
* - update the tabIndex to -1
|
|
992
|
+
* @param {Object} state - The datatable state
|
|
993
|
+
* @param {Node} template - The custom element root `this.template`
|
|
1049
994
|
*/
|
|
1050
|
-
function setBlurActiveRow(
|
|
995
|
+
function setBlurActiveRow(state, template) {
|
|
1051
996
|
if (state.activeCell) {
|
|
1052
997
|
const { rowIndex } = getIndexesActiveCell(state);
|
|
1053
998
|
// eslint-disable-next-line @lwc/lwc/no-async-operation
|
|
1054
999
|
setTimeout(() => {
|
|
1055
|
-
const
|
|
1056
|
-
if (document.activeElement ===
|
|
1057
|
-
|
|
1000
|
+
const rowElement = getActiveCellRowElement(template, state);
|
|
1001
|
+
if (document.activeElement === rowElement) {
|
|
1002
|
+
rowElement.blur();
|
|
1058
1003
|
}
|
|
1059
1004
|
}, 0);
|
|
1060
1005
|
updateRowTabIndex(state, rowIndex, -1);
|
|
@@ -1064,11 +1009,11 @@ function setBlurActiveRow(template, state) {
|
|
|
1064
1009
|
/**
|
|
1065
1010
|
* This method is needed in IE11 where clicking on the cell (factory) makes the div or the span active element
|
|
1066
1011
|
* It refocuses on the cell element td or th or div[role=gridcell/rowheader]
|
|
1067
|
-
* @param {
|
|
1068
|
-
* @param {
|
|
1069
|
-
* @param {
|
|
1012
|
+
* @param {Object} state - The datatable state
|
|
1013
|
+
* @param {Object} template - The datatable element
|
|
1014
|
+
* @param {Boolean} needsRefocusOnCellElement - flag indicating whether or not to refocus on the cell td/th or div[role=gridcell/rowheader]
|
|
1070
1015
|
*/
|
|
1071
|
-
export function refocusCellElement(
|
|
1016
|
+
export function refocusCellElement(state, template, needsRefocusOnCellElement) {
|
|
1072
1017
|
if (needsRefocusOnCellElement) {
|
|
1073
1018
|
const cellElement = getActiveCellElement(template, state);
|
|
1074
1019
|
if (cellElement) {
|
|
@@ -1086,7 +1031,7 @@ export function refocusCellElement(template, state, needsRefocusOnCellElement) {
|
|
|
1086
1031
|
}
|
|
1087
1032
|
|
|
1088
1033
|
export function datatableHasFocus(state, template) {
|
|
1089
|
-
return isFocusInside(template)
|
|
1034
|
+
return state.cellClicked || isFocusInside(template);
|
|
1090
1035
|
}
|
|
1091
1036
|
|
|
1092
1037
|
function isFocusInside(currentTarget) {
|
|
@@ -1150,7 +1095,7 @@ export function handleDatatableFocusOut(event) {
|
|
|
1150
1095
|
|
|
1151
1096
|
/**
|
|
1152
1097
|
* This is needed to check if datatable has lost focus but cell has been clicked recently
|
|
1153
|
-
* @param {
|
|
1098
|
+
* @param {Object} state - The datatable state
|
|
1154
1099
|
*/
|
|
1155
1100
|
export function setCellClickedForFocus(state) {
|
|
1156
1101
|
state.cellClicked = true;
|
|
@@ -1158,7 +1103,7 @@ export function setCellClickedForFocus(state) {
|
|
|
1158
1103
|
|
|
1159
1104
|
/**
|
|
1160
1105
|
* Once the dt regains focus there is no need to set this
|
|
1161
|
-
* @param {
|
|
1106
|
+
* @param {Object} state - The datatable state
|
|
1162
1107
|
*/
|
|
1163
1108
|
function resetCellClickedForFocus(state) {
|
|
1164
1109
|
state.cellClicked = false;
|
|
@@ -1169,18 +1114,18 @@ function resetCellClickedForFocus(state) {
|
|
|
1169
1114
|
/**
|
|
1170
1115
|
* It update the tabIndex value of a cell in the state for the rowIndex, colIndex passed
|
|
1171
1116
|
* as consequence of this change
|
|
1172
|
-
* datatable is gonna re-render the cell affected with the new
|
|
1117
|
+
* datatable is gonna re-render the cell affected with the new tabIndex value
|
|
1173
1118
|
*
|
|
1174
|
-
* @param {
|
|
1119
|
+
* @param {Object} state - The datatable state
|
|
1175
1120
|
* @param {number} rowIndex - the row index
|
|
1176
1121
|
* @param {number} colIndex - the column index
|
|
1177
|
-
* @param {number} [
|
|
1122
|
+
* @param {number} [tabIndex = 0] - the value for the tabIndex
|
|
1178
1123
|
*/
|
|
1179
|
-
export function updateCellTabIndex(state, rowIndex, colIndex,
|
|
1124
|
+
export function updateCellTabIndex(state, rowIndex, colIndex, tabIndex = 0) {
|
|
1180
1125
|
if (isHeaderRow(rowIndex)) {
|
|
1181
|
-
state.columns[colIndex].tabIndex =
|
|
1126
|
+
state.columns[colIndex].tabIndex = tabIndex;
|
|
1182
1127
|
} else {
|
|
1183
|
-
state.rows[rowIndex].cells[colIndex].tabIndex =
|
|
1128
|
+
state.rows[rowIndex].cells[colIndex].tabIndex = tabIndex;
|
|
1184
1129
|
}
|
|
1185
1130
|
}
|
|
1186
1131
|
|
|
@@ -1189,19 +1134,21 @@ export function updateCellTabIndex(state, rowIndex, colIndex, index = 0) {
|
|
|
1189
1134
|
* as consequence of this change
|
|
1190
1135
|
* datatable is gonna re-render the row affected with the new tabindex value
|
|
1191
1136
|
*
|
|
1192
|
-
* @param {
|
|
1137
|
+
* @param {Object} state - The datatable state
|
|
1193
1138
|
* @param {number} rowIndex - the row index
|
|
1194
1139
|
* @param {number} [index = 0] - the value for the tabindex
|
|
1195
1140
|
*/
|
|
1196
|
-
export function updateRowTabIndex(state, rowIndex,
|
|
1141
|
+
export function updateRowTabIndex(state, rowIndex, tabIndex = 0) {
|
|
1197
1142
|
if (!isHeaderRow(rowIndex)) {
|
|
1198
1143
|
// TODO what to do when rowIndex is header row
|
|
1199
|
-
state.rows[rowIndex].tabIndex =
|
|
1144
|
+
state.rows[rowIndex].tabIndex = tabIndex;
|
|
1200
1145
|
}
|
|
1201
1146
|
}
|
|
1147
|
+
|
|
1202
1148
|
/**
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1149
|
+
* Updates the tabIndex for the current activeCell.
|
|
1150
|
+
*
|
|
1151
|
+
* @param {Object} state - The datatable state
|
|
1205
1152
|
* @param {number} [index = 0] - the value for the tabindex
|
|
1206
1153
|
*/
|
|
1207
1154
|
export function updateTabIndexActiveCell(state, index = 0) {
|
|
@@ -1215,11 +1162,10 @@ export function updateTabIndexActiveCell(state, index = 0) {
|
|
|
1215
1162
|
}
|
|
1216
1163
|
|
|
1217
1164
|
/**
|
|
1218
|
-
* It updates the
|
|
1219
|
-
* This happens in rowMode of
|
|
1220
|
-
* @param {
|
|
1165
|
+
* It updates the tabIndex for the row of the current activeCell.
|
|
1166
|
+
* This happens in rowMode of KEYBOARD_NAVIGATION_MODE
|
|
1167
|
+
* @param {Object} state - The datatable state
|
|
1221
1168
|
* @param {number} [index = 0] - the value for the tabindex
|
|
1222
|
-
* @returns {object} state - The datatable state
|
|
1223
1169
|
*/
|
|
1224
1170
|
export function updateTabIndexActiveRow(state, index = 0) {
|
|
1225
1171
|
if (state.activeCell && !stillValidActiveCell(state)) {
|
|
@@ -1228,11 +1174,7 @@ export function updateTabIndexActiveRow(state, index = 0) {
|
|
|
1228
1174
|
}
|
|
1229
1175
|
// Tracked state change.
|
|
1230
1176
|
// We need to check again because maybe there is no active cell after sync.
|
|
1231
|
-
|
|
1232
|
-
const { rowIndex } = getIndexesActiveCell(state);
|
|
1233
|
-
updateRowTabIndex(state, rowIndex, index);
|
|
1234
|
-
}
|
|
1235
|
-
return state;
|
|
1177
|
+
updateActiveRowTabIndexAfterSync(state, index);
|
|
1236
1178
|
}
|
|
1237
1179
|
|
|
1238
1180
|
/***************************** INDEX COMPUTATIONS *****************************/
|
|
@@ -1246,7 +1188,7 @@ export function updateTabIndexActiveRow(state, index = 0) {
|
|
|
1246
1188
|
* @returns {object} - {rowIndex, colIndex}
|
|
1247
1189
|
*/
|
|
1248
1190
|
export function getIndexesByKeys(state, rowKeyValue, colKeyValue) {
|
|
1249
|
-
if (rowKeyValue ===
|
|
1191
|
+
if (rowKeyValue === HEADER_ROW_KEY) {
|
|
1250
1192
|
return {
|
|
1251
1193
|
rowIndex: -1,
|
|
1252
1194
|
colIndex: state.headerIndexes[colKeyValue],
|
|
@@ -1289,8 +1231,8 @@ function getNextIndexLeft(state, colIndex) {
|
|
|
1289
1231
|
}
|
|
1290
1232
|
|
|
1291
1233
|
function getNextIndexUpWrapped(state, rowIndex) {
|
|
1292
|
-
const { length:
|
|
1293
|
-
return rowIndex === -1 ?
|
|
1234
|
+
const { length: rowCount } = state.rows;
|
|
1235
|
+
return rowIndex === -1 ? rowCount - 1 : rowIndex - 1;
|
|
1294
1236
|
}
|
|
1295
1237
|
|
|
1296
1238
|
function getNextIndexDownWrapped(state, rowIndex) {
|
|
@@ -1301,15 +1243,24 @@ function getNextIndexDownWrapped(state, rowIndex) {
|
|
|
1301
1243
|
/***************************** ROW NAVIGATION MODE *****************************/
|
|
1302
1244
|
|
|
1303
1245
|
function canBeRowNavigationMode(state) {
|
|
1304
|
-
return
|
|
1246
|
+
return (
|
|
1247
|
+
state.keyboardMode === KEYBOARD_NAVIGATION_MODE &&
|
|
1248
|
+
hasTreeDataType(state)
|
|
1249
|
+
);
|
|
1305
1250
|
}
|
|
1306
1251
|
|
|
1307
1252
|
function isRowNavigationMode(state) {
|
|
1308
|
-
return
|
|
1253
|
+
return (
|
|
1254
|
+
state.keyboardMode === KEYBOARD_NAVIGATION_MODE &&
|
|
1255
|
+
state.rowMode === true
|
|
1256
|
+
);
|
|
1309
1257
|
}
|
|
1310
1258
|
|
|
1311
1259
|
function setRowNavigationMode(state) {
|
|
1312
|
-
if (
|
|
1260
|
+
if (
|
|
1261
|
+
hasTreeDataType(state) &&
|
|
1262
|
+
state.keyboardMode === KEYBOARD_NAVIGATION_MODE
|
|
1263
|
+
) {
|
|
1313
1264
|
state.rowMode = true;
|
|
1314
1265
|
}
|
|
1315
1266
|
}
|
|
@@ -1319,14 +1270,14 @@ export function unsetRowNavigationMode(state) {
|
|
|
1319
1270
|
}
|
|
1320
1271
|
|
|
1321
1272
|
/**
|
|
1322
|
-
* If new set of columns
|
|
1273
|
+
* If new set of columns doesn't have tree data, mark it to false, as it
|
|
1323
1274
|
* could be true earlier
|
|
1324
1275
|
* Else if it has tree data, check if rowMode is false
|
|
1325
|
-
* Earlier it
|
|
1276
|
+
* Earlier it didn't have tree data, set rowMode to true to start
|
|
1326
1277
|
* if rowMode is false and earlier it has tree data, keep it false
|
|
1327
1278
|
* if rowMode is true and it has tree data, keep it true
|
|
1328
|
-
* @param {
|
|
1329
|
-
* @param {
|
|
1279
|
+
* @param {Boolean} hadTreeDataTypePreviously - state object
|
|
1280
|
+
* @param {Object} state - The state object
|
|
1330
1281
|
*/
|
|
1331
1282
|
export function updateRowNavigationMode(hadTreeDataTypePreviously, state) {
|
|
1332
1283
|
if (!hasTreeDataType(state)) {
|
|
@@ -1338,10 +1289,10 @@ export function updateRowNavigationMode(hadTreeDataTypePreviously, state) {
|
|
|
1338
1289
|
|
|
1339
1290
|
/***************************** HELPER FUNCTIONS *****************************/
|
|
1340
1291
|
|
|
1341
|
-
export function isCellElement(
|
|
1292
|
+
export function isCellElement(target) {
|
|
1293
|
+
const role = target.getAttribute('role');
|
|
1342
1294
|
return (
|
|
1343
|
-
|
|
1344
|
-
SELECTORS.cell.roleBased.includes(role)
|
|
1295
|
+
role === 'gridcell' || role === 'columnheader' || role === 'rowheader'
|
|
1345
1296
|
);
|
|
1346
1297
|
}
|
|
1347
1298
|
|
|
@@ -1349,26 +1300,22 @@ function isHeaderRow(rowIndex) {
|
|
|
1349
1300
|
return rowIndex === -1;
|
|
1350
1301
|
}
|
|
1351
1302
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
export function getCellElementByKeys(template, rowKeyValue, colKeyValue) {
|
|
1357
|
-
const selector = `${getRowDataSelector(
|
|
1358
|
-
rowKeyValue
|
|
1359
|
-
)} [data-col-key-value="${escapeDoubleQuotes(
|
|
1303
|
+
function getCellElementByKeys(template, rowKeyValue, colKeyValue) {
|
|
1304
|
+
const selector = `${getRowDataSelector(rowKeyValue)} ${getColDataSelector(
|
|
1360
1305
|
colKeyValue
|
|
1361
|
-
)}
|
|
1306
|
+
)} > :first-child`;
|
|
1362
1307
|
return template.querySelector(selector);
|
|
1363
1308
|
}
|
|
1364
1309
|
|
|
1365
1310
|
function getActiveCellRowElement(template, state) {
|
|
1311
|
+
let result;
|
|
1366
1312
|
const { activeCell } = state;
|
|
1367
1313
|
if (activeCell) {
|
|
1368
|
-
|
|
1369
|
-
|
|
1314
|
+
result = template.querySelector(
|
|
1315
|
+
getRowDataSelector(activeCell.rowKeyValue)
|
|
1316
|
+
);
|
|
1370
1317
|
}
|
|
1371
|
-
return null;
|
|
1318
|
+
return result || null;
|
|
1372
1319
|
}
|
|
1373
1320
|
|
|
1374
1321
|
export function getRowParentIndex(state, rowLevel, rowIndex) {
|
|
@@ -1382,19 +1329,8 @@ export function getRowParentIndex(state, rowLevel, rowIndex) {
|
|
|
1382
1329
|
return -1;
|
|
1383
1330
|
}
|
|
1384
1331
|
|
|
1385
|
-
function getCellFromIndexes(state, rowIndex, colIndex) {
|
|
1386
|
-
const { columns, rows } = state;
|
|
1387
|
-
if (columns.length > 0) {
|
|
1388
|
-
return {
|
|
1389
|
-
rowKeyValue: rowIndex === -1 ? HEADER_ROW : rows[rowIndex].key,
|
|
1390
|
-
colKeyValue: generateColKeyValue(columns[colIndex], colIndex),
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
return undefined;
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
1332
|
function updateScrollTop(state, template, element) {
|
|
1397
|
-
const scrollableY = template
|
|
1333
|
+
const scrollableY = getScrollerY(template);
|
|
1398
1334
|
const scrollingParent = scrollableY.parentElement;
|
|
1399
1335
|
const parentRect = scrollingParent.getBoundingClientRect();
|
|
1400
1336
|
const findMeRect = element.getBoundingClientRect();
|
|
@@ -1416,7 +1352,7 @@ function scrollToCell(state, template, rowIndex) {
|
|
|
1416
1352
|
scrollTop = Math.max(scrollTop - rowsInViewport * rowHeight, 0);
|
|
1417
1353
|
}
|
|
1418
1354
|
|
|
1419
|
-
const scrollableY = template
|
|
1355
|
+
const scrollableY = getScrollerY(template);
|
|
1420
1356
|
scrollableY.scrollTop = scrollTop;
|
|
1421
1357
|
findFirstVisibleIndex(state, scrollTop);
|
|
1422
1358
|
}
|
|
@@ -1430,7 +1366,7 @@ export function isActiveCellEditable(state) {
|
|
|
1430
1366
|
}
|
|
1431
1367
|
|
|
1432
1368
|
export function isValidCell(state, rowKeyValue, colKeyValue) {
|
|
1433
|
-
if (rowKeyValue ===
|
|
1369
|
+
if (rowKeyValue === HEADER_ROW_KEY) {
|
|
1434
1370
|
return state.headerIndexes[colKeyValue] !== undefined;
|
|
1435
1371
|
}
|
|
1436
1372
|
const row = getRowByKey(state, rowKeyValue);
|
|
@@ -1457,3 +1393,11 @@ export function updateActiveCellTabIndexAfterSync(state, tabIndex = 0) {
|
|
|
1457
1393
|
updateCellTabIndex(state, rowIndex, colIndex, tabIndex);
|
|
1458
1394
|
}
|
|
1459
1395
|
}
|
|
1396
|
+
|
|
1397
|
+
export function updateActiveRowTabIndexAfterSync(state, tabIndex = 0) {
|
|
1398
|
+
const { activeCell } = state;
|
|
1399
|
+
if (activeCell && isRowNavigationMode(state)) {
|
|
1400
|
+
const { rowIndex } = getIndexesActiveCell(state);
|
|
1401
|
+
updateRowTabIndex(state, rowIndex, tabIndex);
|
|
1402
|
+
}
|
|
1403
|
+
}
|