@salesforce/design-system-react 0.10.44 → 0.10.47
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/components/button/__tests__/button.browser-test.jsx +0 -1
- package/components/combobox/combobox.d.ts +3 -0
- package/components/combobox/combobox.jsx +4 -1
- package/components/component-docs.json +6 -3
- package/components/data-table/cell.jsx +2 -2
- package/components/data-table/index.jsx +134 -85
- package/components/data-table/private/context-helper.js +26 -14
- package/components/data-table/private/head.jsx +269 -260
- package/components/data-table/private/header-cell.jsx +204 -230
- package/components/data-table/private/row.jsx +140 -105
- package/components/data-table/row-actions.jsx +2 -2
- package/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
- package/components/pill-container/private/selected-listbox.jsx +1 -0
- package/components/popover/__tests__/popover.browser-test.jsx +28 -0
- package/components/progress-indicator.d.ts +29 -8
- package/components/slider.d.ts +10 -4
- package/components/utilities/truncate/index.jsx +1 -1
- package/design-system-react-components.js +62406 -0
- package/design-system-react-components.js.map +1 -0
- package/design-system-react-components.min.js +3 -0
- package/design-system-react-components.min.js.LICENSE.txt +83 -0
- package/design-system-react-components.min.js.map +1 -0
- package/design-system-react.js +73800 -0
- package/design-system-react.js.map +1 -0
- package/design-system-react.min.js +3 -0
- package/design-system-react.min.js.LICENSE.txt +83 -0
- package/design-system-react.min.js.map +1 -0
- package/lib/components/button/__tests__/button.browser-test.jsx +0 -1
- package/lib/components/combobox/combobox.d.ts +3 -0
- package/lib/components/combobox/combobox.js +4 -1
- package/lib/components/component-docs.json +6 -3
- package/lib/components/data-table/cell.js +6 -6
- package/lib/components/data-table/index.js +131 -99
- package/lib/components/data-table/private/context-helper.js +13 -14
- package/lib/components/data-table/private/head.js +233 -252
- package/lib/components/data-table/private/header-cell.js +185 -221
- package/lib/components/data-table/private/row.js +97 -89
- package/lib/components/data-table/row-actions.js +6 -6
- package/lib/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
- package/lib/components/pill-container/private/selected-listbox.js +3 -0
- package/lib/components/popover/__tests__/popover.browser-test.jsx +28 -0
- package/lib/components/progress-indicator.d.ts +29 -8
- package/lib/components/slider.d.ts +10 -4
- package/lib/components/utilities/truncate/index.js +2 -2
- package/lib/design-system-react-components.min.js.LICENSE.txt +83 -0
- package/lib/design-system-react.min.js.LICENSE.txt +83 -0
- package/lib/package.json +5 -5
- package/lib/utilities/keyboard-navigable-dialog.js +6 -1
- package/module/components/button/__tests__/button.browser-test.js +0 -1
- package/module/components/button/__tests__/button.browser-test.js.map +1 -1
- package/module/components/combobox/combobox.d.ts +3 -0
- package/module/components/combobox/combobox.js +4 -1
- package/module/components/combobox/combobox.js.map +1 -1
- package/module/components/component-docs.json +6 -3
- package/module/components/data-table/cell.js +6 -6
- package/module/components/data-table/cell.js.map +1 -1
- package/module/components/data-table/index.js +124 -95
- package/module/components/data-table/index.js.map +1 -1
- package/module/components/data-table/private/context-helper.js +12 -12
- package/module/components/data-table/private/context-helper.js.map +1 -1
- package/module/components/data-table/private/head.js +230 -255
- package/module/components/data-table/private/head.js.map +1 -1
- package/module/components/data-table/private/header-cell.js +184 -225
- package/module/components/data-table/private/header-cell.js.map +1 -1
- package/module/components/data-table/private/row.js +95 -87
- package/module/components/data-table/private/row.js.map +1 -1
- package/module/components/data-table/row-actions.js +6 -6
- package/module/components/data-table/row-actions.js.map +1 -1
- package/module/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
- package/module/components/pill-container/private/selected-listbox.js +3 -0
- package/module/components/pill-container/private/selected-listbox.js.map +1 -1
- package/module/components/popover/__tests__/popover.browser-test.js +25 -0
- package/module/components/popover/__tests__/popover.browser-test.js.map +1 -1
- package/module/components/progress-indicator.d.ts +29 -8
- package/module/components/slider.d.ts +10 -4
- package/module/components/utilities/truncate/index.js +1 -1
- package/module/components/utilities/truncate/index.js.map +1 -1
- package/module/utilities/keyboard-navigable-dialog.js +4 -1
- package/module/utilities/keyboard-navigable-dialog.js.map +1 -1
- package/package.json +5 -5
- package/utilities/keyboard-navigable-dialog.js +3 -0
|
@@ -162,6 +162,7 @@ declare module '@salesforce/design-system-react/components/combobox/combobox' {
|
|
|
162
162
|
* * `id`: A unique identifier string.
|
|
163
163
|
* * `label`: A primary string of text for a menu item or group separator.
|
|
164
164
|
* * `subTitle`: A secondary string of text added for clarity. (optional)
|
|
165
|
+
* * `title`: A string of text shown as the title of the selected item (optional)
|
|
165
166
|
* * `type`: 'separator' is the only type currently used
|
|
166
167
|
* * `disabled`: Set to true to disable this menu item.
|
|
167
168
|
* * `tooltipContent`: Content that is displayed in tooltip when item is disabled
|
|
@@ -170,6 +171,7 @@ declare module '@salesforce/design-system-react/components/combobox/combobox' {
|
|
|
170
171
|
* id: '2',
|
|
171
172
|
* label: 'Salesforce.com, Inc.',
|
|
172
173
|
* subTitle: 'Account • San Francisco',
|
|
174
|
+
* title: 'Salesforce',
|
|
173
175
|
* type: 'account',
|
|
174
176
|
* disabled: true,
|
|
175
177
|
* tooltipContent: "You don't have permission to select this item."
|
|
@@ -182,6 +184,7 @@ declare module '@salesforce/design-system-react/components/combobox/combobox' {
|
|
|
182
184
|
icon?: React.ReactNode;
|
|
183
185
|
label?: string;
|
|
184
186
|
subTitle?: string;
|
|
187
|
+
title?: string;
|
|
185
188
|
type?: string;
|
|
186
189
|
disabled?: boolean;
|
|
187
190
|
tooltipContent?: React.ReactNode;
|
|
@@ -235,6 +235,7 @@ const propTypes = {
|
|
|
235
235
|
* * `id`: A unique identifier string.
|
|
236
236
|
* * `label`: A primary string of text for a menu item or group separator.
|
|
237
237
|
* * `subTitle`: A secondary string of text added for clarity. (optional)
|
|
238
|
+
* * `title`: A string of text shown as the title of the selected item (optional)
|
|
238
239
|
* * `type`: 'separator' is the only type currently used
|
|
239
240
|
* * `disabled`: Set to true to disable this menu item.
|
|
240
241
|
* * `tooltipContent`: Content that is displayed in tooltip when item is disabled
|
|
@@ -243,6 +244,7 @@ const propTypes = {
|
|
|
243
244
|
* id: '2',
|
|
244
245
|
* label: 'Salesforce.com, Inc.',
|
|
245
246
|
* subTitle: 'Account • San Francisco',
|
|
247
|
+
* title: 'Salesforce',
|
|
246
248
|
* type: 'account',
|
|
247
249
|
* disabled: true,
|
|
248
250
|
* tooltipContent: "You don't have permission to select this item."
|
|
@@ -256,8 +258,9 @@ const propTypes = {
|
|
|
256
258
|
icon: PropTypes.node,
|
|
257
259
|
label: PropTypes.string,
|
|
258
260
|
subTitle: PropTypes.string,
|
|
261
|
+
title: PropTypes.string,
|
|
259
262
|
type: PropTypes.string,
|
|
260
|
-
disabled: PropTypes.
|
|
263
|
+
disabled: PropTypes.bool,
|
|
261
264
|
tooltipContent: PropTypes.node,
|
|
262
265
|
})
|
|
263
266
|
),
|
|
@@ -4958,13 +4958,16 @@
|
|
|
4958
4958
|
"name": "string",
|
|
4959
4959
|
"required": false
|
|
4960
4960
|
},
|
|
4961
|
+
"title": {
|
|
4962
|
+
"name": "string",
|
|
4963
|
+
"required": false
|
|
4964
|
+
},
|
|
4961
4965
|
"type": {
|
|
4962
4966
|
"name": "string",
|
|
4963
4967
|
"required": false
|
|
4964
4968
|
},
|
|
4965
4969
|
"disabled": {
|
|
4966
|
-
"name": "
|
|
4967
|
-
"raw": "PropTypes.boolean",
|
|
4970
|
+
"name": "bool",
|
|
4968
4971
|
"required": false
|
|
4969
4972
|
},
|
|
4970
4973
|
"tooltipContent": {
|
|
@@ -4975,7 +4978,7 @@
|
|
|
4975
4978
|
}
|
|
4976
4979
|
},
|
|
4977
4980
|
"required": false,
|
|
4978
|
-
"description": "**Array of item objects in the dropdown menu.**\nEach object can contain:\n* `icon`: An `Icon` component. (not used in read-only variant)\n* `id`: A unique identifier string.\n* `label`: A primary string of text for a menu item or group separator.\n* `subTitle`: A secondary string of text added for clarity. (optional)\n* `type`: 'separator' is the only type currently used\n* `disabled`: Set to true to disable this menu item.\n* `tooltipContent`: Content that is displayed in tooltip when item is disabled\n```\n{\n\tid: '2',\n\tlabel: 'Salesforce.com, Inc.',\n\tsubTitle: 'Account • San Francisco',\n\ttype: 'account',\n disabled: true,\n tooltipContent: \"You don't have permission to select this item.\"\n},\n```\nNote: At the moment, Combobox does not support two consecutive separators. _Tested with snapshot testing._"
|
|
4981
|
+
"description": "**Array of item objects in the dropdown menu.**\nEach object can contain:\n* `icon`: An `Icon` component. (not used in read-only variant)\n* `id`: A unique identifier string.\n* `label`: A primary string of text for a menu item or group separator.\n* `subTitle`: A secondary string of text added for clarity. (optional)\n* `title`: A string of text shown as the title of the selected item (optional)\n* `type`: 'separator' is the only type currently used\n* `disabled`: Set to true to disable this menu item.\n* `tooltipContent`: Content that is displayed in tooltip when item is disabled\n```\n{\n\tid: '2',\n\tlabel: 'Salesforce.com, Inc.',\n\tsubTitle: 'Account • San Francisco',\n\ttitle: 'Salesforce',\n\ttype: 'account',\n disabled: true,\n tooltipContent: \"You don't have permission to select this item.\"\n},\n```\nNote: At the moment, Combobox does not support two consecutive separators. _Tested with snapshot testing._"
|
|
4979
4982
|
},
|
|
4980
4983
|
"menuItemVisibleLength": {
|
|
4981
4984
|
"type": {
|
|
@@ -10,7 +10,7 @@ import classNames from 'classnames';
|
|
|
10
10
|
|
|
11
11
|
import CellContext from './private/cell-context';
|
|
12
12
|
import TableContext from './private/table-context';
|
|
13
|
-
import
|
|
13
|
+
import useContextHelper from './private/context-helper';
|
|
14
14
|
|
|
15
15
|
// ## Constants
|
|
16
16
|
import { DATA_TABLE_CELL } from '../../utilities/constants';
|
|
@@ -21,7 +21,7 @@ import { DATA_TABLE_CELL } from '../../utilities/constants';
|
|
|
21
21
|
const DataTableCell = (props) => {
|
|
22
22
|
const tableContext = useContext(TableContext);
|
|
23
23
|
const cellContext = useContext(CellContext);
|
|
24
|
-
const { tabIndex, hasFocus, handleFocus, handleKeyDown } =
|
|
24
|
+
const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
|
|
25
25
|
tableContext,
|
|
26
26
|
cellContext,
|
|
27
27
|
props.fixedLayout
|
|
@@ -16,8 +16,9 @@ import shortid from 'shortid';
|
|
|
16
16
|
|
|
17
17
|
import classNames from 'classnames';
|
|
18
18
|
import assign from 'lodash.assign';
|
|
19
|
+
import isEqual from 'lodash.isequal';
|
|
20
|
+
import memoize from 'memoize-one';
|
|
19
21
|
import reject from 'lodash.reject';
|
|
20
|
-
|
|
21
22
|
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
|
|
22
23
|
import ColumnResizer from 'column-resizer';
|
|
23
24
|
import checkProps from './check-props';
|
|
@@ -74,6 +75,93 @@ const defaultProps = {
|
|
|
74
75
|
},
|
|
75
76
|
};
|
|
76
77
|
|
|
78
|
+
const getAssistiveText = memoize(
|
|
79
|
+
(
|
|
80
|
+
assistiveText,
|
|
81
|
+
actionsHeaderText,
|
|
82
|
+
columnSortText,
|
|
83
|
+
columnSortedAscendingText,
|
|
84
|
+
columnSortedDescendingText,
|
|
85
|
+
selectAllRowsText,
|
|
86
|
+
selectRowText
|
|
87
|
+
) => {
|
|
88
|
+
const result = {
|
|
89
|
+
...defaultProps.assistiveText,
|
|
90
|
+
...assistiveText,
|
|
91
|
+
};
|
|
92
|
+
if (actionsHeaderText) {
|
|
93
|
+
result.actionsHeader = actionsHeaderText;
|
|
94
|
+
}
|
|
95
|
+
if (selectAllRowsText) {
|
|
96
|
+
result.selectAllRows = selectAllRowsText;
|
|
97
|
+
}
|
|
98
|
+
if (columnSortedAscendingText) {
|
|
99
|
+
result.columnSortedAscending = columnSortedAscendingText;
|
|
100
|
+
}
|
|
101
|
+
if (columnSortedDescendingText) {
|
|
102
|
+
result.columnSortedDescending = columnSortedDescendingText;
|
|
103
|
+
}
|
|
104
|
+
if (columnSortText) {
|
|
105
|
+
result.columnSort = columnSortText;
|
|
106
|
+
}
|
|
107
|
+
if (selectRowText) {
|
|
108
|
+
result.selectRow = selectRowText;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
},
|
|
112
|
+
isEqual
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const getColumnsAndRowActions = memoize(
|
|
116
|
+
(children, id, fixedHeader, fixedLayout, items, search) => {
|
|
117
|
+
const columns = [];
|
|
118
|
+
let RowActions = null;
|
|
119
|
+
|
|
120
|
+
React.Children.forEach(children, (child) => {
|
|
121
|
+
if (child && child.type.displayName === DataTableColumn.displayName) {
|
|
122
|
+
const { children: columnChildren, ...columnProps } = child.props;
|
|
123
|
+
const props = { fixedLayout, search, items, ...columnProps };
|
|
124
|
+
if (id) {
|
|
125
|
+
props.id = id;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let Cell;
|
|
129
|
+
if (
|
|
130
|
+
columnChildren &&
|
|
131
|
+
columnChildren.type.displayName === DATA_TABLE_CELL
|
|
132
|
+
) {
|
|
133
|
+
Cell = columnChildren.type;
|
|
134
|
+
assign(props, columnChildren.props);
|
|
135
|
+
} else {
|
|
136
|
+
Cell = DataTableCell;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
140
|
+
columns.push({
|
|
141
|
+
Cell,
|
|
142
|
+
props,
|
|
143
|
+
});
|
|
144
|
+
} else if (
|
|
145
|
+
child &&
|
|
146
|
+
child.type.displayName === DataTableRowActions.displayName
|
|
147
|
+
) {
|
|
148
|
+
const { dropdown } = child.props;
|
|
149
|
+
const dropdownPropOverrides = {};
|
|
150
|
+
if (fixedHeader) {
|
|
151
|
+
dropdownPropOverrides.menuPosition = 'overflowBoundaryElement';
|
|
152
|
+
}
|
|
153
|
+
RowActions = React.cloneElement(child, {
|
|
154
|
+
dropdown: dropdown
|
|
155
|
+
? React.cloneElement(dropdown, dropdownPropOverrides)
|
|
156
|
+
: null,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return { columns, RowActions };
|
|
161
|
+
},
|
|
162
|
+
isEqual
|
|
163
|
+
);
|
|
164
|
+
|
|
77
165
|
/**
|
|
78
166
|
* DataTables support the display of structured data in rows and columns with an HTML table. To sort, filter or paginate the table, simply update the data passed in the items to the table and it will re-render itself appropriately. The table will throw a sort event as needed, and helper components for paging and filtering are coming soon.
|
|
79
167
|
*
|
|
@@ -366,9 +454,7 @@ class DataTable extends React.Component {
|
|
|
366
454
|
// Simulating a scroll here will ensure that enough rows are loaded to enable scrolling
|
|
367
455
|
this.loadMoreIfNeeded();
|
|
368
456
|
}
|
|
369
|
-
|
|
370
|
-
this.interactiveElements = {};
|
|
371
|
-
}
|
|
457
|
+
|
|
372
458
|
if (
|
|
373
459
|
this.state.allowKeyboardNavigation &&
|
|
374
460
|
!prevState.allowKeyboardNavigation
|
|
@@ -440,6 +526,23 @@ class DataTable extends React.Component {
|
|
|
440
526
|
return null;
|
|
441
527
|
}
|
|
442
528
|
|
|
529
|
+
getTableContext = memoize((state, isKeyboardNavigation) => ({
|
|
530
|
+
activeCell: state.activeCell,
|
|
531
|
+
activeElement: state.activeElement,
|
|
532
|
+
mode: state.mode,
|
|
533
|
+
tableHasFocus: state.tableHasFocus,
|
|
534
|
+
changeActiveCell: this.changeActiveCell,
|
|
535
|
+
changeActiveElement: this.changeActiveElement,
|
|
536
|
+
handleKeyDown: this.handleKeyDown,
|
|
537
|
+
registerInteractiveElement: this.registerInteractiveElement,
|
|
538
|
+
allowKeyboardNavigation: state.allowKeyboardNavigation,
|
|
539
|
+
setAllowKeyboardNavigation: (allowKeyboardNavigation) => {
|
|
540
|
+
if (isKeyboardNavigation) {
|
|
541
|
+
this.setState({ allowKeyboardNavigation });
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
}));
|
|
545
|
+
|
|
443
546
|
handleToggleAll = (e, { checked }) => {
|
|
444
547
|
// REMOVE AT NEXT BREAKING CHANGE
|
|
445
548
|
// `onChange` is deprecated and replaced with `onRowChange`
|
|
@@ -587,6 +690,13 @@ class DataTable extends React.Component {
|
|
|
587
690
|
}
|
|
588
691
|
};
|
|
589
692
|
|
|
693
|
+
// eslint-disable-next-line camelcase
|
|
694
|
+
UNSAFE_componentWillUpdate(nextProps) {
|
|
695
|
+
if (this.props.items !== nextProps.items) {
|
|
696
|
+
this.interactiveElements = {};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
590
700
|
isResizable() {
|
|
591
701
|
return this.props.fixedLayout && this.props.resizable;
|
|
592
702
|
}
|
|
@@ -989,71 +1099,25 @@ class DataTable extends React.Component {
|
|
|
989
1099
|
const allSelected = canSelectRows && numNonHeaderRows === numSelected;
|
|
990
1100
|
const indeterminateSelected =
|
|
991
1101
|
canSelectRows && numNonHeaderRows !== numSelected && numSelected !== 0;
|
|
992
|
-
const columns = [];
|
|
993
|
-
let RowActions = null;
|
|
994
1102
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
let Cell;
|
|
1005
|
-
if (children && children.type.displayName === DATA_TABLE_CELL) {
|
|
1006
|
-
Cell = children.type;
|
|
1007
|
-
assign(props, children.props);
|
|
1008
|
-
} else {
|
|
1009
|
-
Cell = DataTableCell;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// eslint-disable-next-line fp/no-mutating-methods
|
|
1013
|
-
columns.push({
|
|
1014
|
-
Cell,
|
|
1015
|
-
props,
|
|
1016
|
-
dataTableProps: this.props,
|
|
1017
|
-
});
|
|
1018
|
-
} else if (
|
|
1019
|
-
child &&
|
|
1020
|
-
child.type.displayName === DataTableRowActions.displayName
|
|
1021
|
-
) {
|
|
1022
|
-
const { dropdown } = child.props;
|
|
1023
|
-
const dropdownPropOverrides = {};
|
|
1024
|
-
if (this.getFixedHeader()) {
|
|
1025
|
-
dropdownPropOverrides.menuPosition = 'overflowBoundaryElement';
|
|
1026
|
-
}
|
|
1027
|
-
RowActions = React.cloneElement(child, {
|
|
1028
|
-
dropdown: dropdown
|
|
1029
|
-
? React.cloneElement(dropdown, dropdownPropOverrides)
|
|
1030
|
-
: null,
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1103
|
+
const { columns, RowActions } = getColumnsAndRowActions(
|
|
1104
|
+
this.props.children,
|
|
1105
|
+
this.props.id,
|
|
1106
|
+
this.getFixedHeader(),
|
|
1107
|
+
this.props.fixedLayout,
|
|
1108
|
+
this.props.items,
|
|
1109
|
+
this.props.search
|
|
1110
|
+
);
|
|
1034
1111
|
|
|
1035
|
-
const assistiveText =
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
if (this.props.assistiveTextForColumnSortedAscending) {
|
|
1046
|
-
assistiveText.columnSortedAscending = this.props.assistiveTextForColumnSortedAscending;
|
|
1047
|
-
}
|
|
1048
|
-
if (this.props.assistiveTextForColumnSortedDescending) {
|
|
1049
|
-
assistiveText.columnSortedDescending = this.props.assistiveTextForColumnSortedDescending;
|
|
1050
|
-
}
|
|
1051
|
-
if (this.props.assistiveTextForColumnSort) {
|
|
1052
|
-
assistiveText.columnSort = this.props.assistiveTextForColumnSort;
|
|
1053
|
-
}
|
|
1054
|
-
if (this.props.assistiveTextForSelectRow) {
|
|
1055
|
-
assistiveText.selectRow = this.props.assistiveTextForSelectRow;
|
|
1056
|
-
}
|
|
1112
|
+
const assistiveText = getAssistiveText(
|
|
1113
|
+
this.props.assistiveText,
|
|
1114
|
+
this.props.assistiveTextForActionsHeader,
|
|
1115
|
+
this.props.assistiveTextForSelectAllRows,
|
|
1116
|
+
this.props.assistiveTextForColumnSortedAscending,
|
|
1117
|
+
this.props.assistiveTextForColumnSortedDescending,
|
|
1118
|
+
this.props.assistiveTextForColumnSort,
|
|
1119
|
+
this.props.assistiveTextForSelectRow
|
|
1120
|
+
);
|
|
1057
1121
|
|
|
1058
1122
|
if (this.props.selectRows && this.props.selectRows !== 'radio') {
|
|
1059
1123
|
ariaProps['aria-multiselectable'] = 'true';
|
|
@@ -1066,26 +1130,11 @@ class DataTable extends React.Component {
|
|
|
1066
1130
|
select: canSelectRows ? this.headerRefs.select : [],
|
|
1067
1131
|
};
|
|
1068
1132
|
|
|
1069
|
-
const tableContext = {
|
|
1070
|
-
activeCell: this.state.activeCell,
|
|
1071
|
-
activeElement: this.state.activeElement,
|
|
1072
|
-
mode: this.state.mode,
|
|
1073
|
-
tableHasFocus: this.state.tableHasFocus,
|
|
1074
|
-
changeActiveCell: this.changeActiveCell,
|
|
1075
|
-
changeActiveElement: this.changeActiveElement,
|
|
1076
|
-
handleKeyDown: this.handleKeyDown,
|
|
1077
|
-
registerInteractiveElement: this.registerInteractiveElement,
|
|
1078
|
-
allowKeyboardNavigation: this.state.allowKeyboardNavigation,
|
|
1079
|
-
setAllowKeyboardNavigation: (allowKeyboardNavigation) => {
|
|
1080
|
-
if (this.getKeyboardNavigation()) {
|
|
1081
|
-
this.setState({ allowKeyboardNavigation });
|
|
1082
|
-
}
|
|
1083
|
-
},
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
1133
|
let component = (
|
|
1087
1134
|
<React.Fragment>
|
|
1088
|
-
<TableContext.Provider
|
|
1135
|
+
<TableContext.Provider
|
|
1136
|
+
value={this.getTableContext(this.state, this.getKeyboardNavigation())}
|
|
1137
|
+
>
|
|
1089
1138
|
<table
|
|
1090
1139
|
{...ariaProps}
|
|
1091
1140
|
className={classNames(
|
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
|
|
2
2
|
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
|
|
3
3
|
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Calculates data table keyboard navigation state based on currently selected cell
|
|
6
8
|
*/
|
|
7
|
-
export default (
|
|
9
|
+
export default function useTableContextHelper(
|
|
10
|
+
tableContext,
|
|
11
|
+
cellContext,
|
|
12
|
+
fixedLayout
|
|
13
|
+
) {
|
|
8
14
|
const isActive =
|
|
9
15
|
tableContext.activeCell.rowIndex === cellContext.rowIndex &&
|
|
10
16
|
tableContext.activeCell.columnIndex === cellContext.columnIndex;
|
|
11
17
|
|
|
12
18
|
const hasFocus = fixedLayout && tableContext.tableHasFocus && isActive;
|
|
13
|
-
|
|
14
|
-
const handleFocus = () => {
|
|
19
|
+
const { changeActiveCell, handleKeyDown: handleTableKeyDown } = tableContext;
|
|
20
|
+
const handleFocus = useCallback(() => {
|
|
15
21
|
if (fixedLayout && tableContext.allowKeyboardNavigation) {
|
|
16
|
-
|
|
17
|
-
cellContext.rowIndex,
|
|
18
|
-
cellContext.columnIndex
|
|
19
|
-
);
|
|
22
|
+
changeActiveCell(cellContext.rowIndex, cellContext.columnIndex);
|
|
20
23
|
}
|
|
21
|
-
}
|
|
24
|
+
}, [
|
|
25
|
+
fixedLayout,
|
|
26
|
+
tableContext.allowKeyboardNavigation,
|
|
27
|
+
changeActiveCell,
|
|
28
|
+
cellContext.rowIndex,
|
|
29
|
+
cellContext.columnIndex,
|
|
30
|
+
]);
|
|
22
31
|
|
|
23
|
-
const handleKeyDown = (
|
|
24
|
-
|
|
25
|
-
tableContext.
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
const handleKeyDown = useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
if (fixedLayout && tableContext.allowKeyboardNavigation) {
|
|
35
|
+
handleTableKeyDown(event);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
[fixedLayout, tableContext.allowKeyboardNavigation, handleTableKeyDown]
|
|
39
|
+
);
|
|
28
40
|
|
|
29
41
|
const tabIndex =
|
|
30
42
|
fixedLayout &&
|
|
@@ -35,4 +47,4 @@ export default (tableContext, cellContext, fixedLayout) => {
|
|
|
35
47
|
: undefined;
|
|
36
48
|
|
|
37
49
|
return { tabIndex, hasFocus, handleFocus, handleKeyDown };
|
|
38
|
-
}
|
|
50
|
+
}
|