@salesforce/design-system-react 0.10.35 → 0.10.39

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.
Files changed (172) hide show
  1. package/assets/styles/table.css +70 -0
  2. package/components/builder-header/utilities.d.ts +20 -0
  3. package/components/card/__docs__/__snapshots__/storybook-stories.storyshot +20 -5
  4. package/components/combobox/__docs__/__snapshots__/storybook-stories.storyshot +178 -169
  5. package/components/combobox/__tests__/combobox.browser-test.jsx +4 -5
  6. package/components/combobox/combobox.jsx +20 -18
  7. package/components/component-docs.json +160 -0
  8. package/components/data-table/__docs__/__snapshots__/storybook-stories.storyshot +17997 -11862
  9. package/components/data-table/__docs__/storybook-stories.jsx +5 -1
  10. package/components/data-table/__examples__/advanced-single-select-fixed-header.jsx +1 -0
  11. package/components/data-table/__examples__/basic-fluid-headless.jsx +105 -0
  12. package/components/data-table/__examples__/interactive-elements.jsx +14 -0
  13. package/components/data-table/__examples__/joined-with-page-header.jsx +11 -18
  14. package/components/data-table/__examples__/resizable-columns.jsx +237 -0
  15. package/components/data-table/__tests__/data-table.browser-test.jsx +133 -0
  16. package/components/data-table/column.resizer.d.ts +1 -0
  17. package/components/data-table/component.json +11 -7
  18. package/components/data-table/index.jsx +431 -80
  19. package/components/data-table/private/head.jsx +8 -3
  20. package/components/data-table/private/header-cell.jsx +9 -1
  21. package/components/data-table.d.ts +8 -0
  22. package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +17 -17
  23. package/components/expression/__docs__/__snapshots__/storybook-stories.storyshot +90 -90
  24. package/components/global-header/__docs__/__snapshots__/storybook-stories.storyshot +9 -9
  25. package/components/index.d.ts +2 -0
  26. package/components/menu-dropdown/__docs__/__snapshots__/storybook-stories.storyshot +552 -26
  27. package/components/menu-dropdown/__docs__/storybook-stories.jsx +4 -16
  28. package/components/menu-dropdown/__examples__/checkmark.jsx +48 -31
  29. package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +12 -7
  30. package/components/modal/__tests__/modal.browser-test.jsx +4 -10
  31. package/components/portal-settings/__docs__/__snapshots__/storybook-stories.storyshot +6 -6
  32. package/components/progress-indicator/__docs__/__snapshots__/storybook-stories.storyshot +161 -14
  33. package/components/progress-indicator/private/step-vertical.jsx +28 -2
  34. package/components/setup-assistant/__docs__/__snapshots__/storybook-stories.storyshot +180 -13
  35. package/components/site-stories.js +16 -4
  36. package/components/utilities/menu-list/index.jsx +3 -0
  37. package/components/utilities/menu-list/item.jsx +5 -2
  38. package/components/vertical-navigation/__docs__/__snapshots__/storybook-stories.storyshot +326 -0
  39. package/components/vertical-navigation/__docs__/storybook-stories.jsx +4 -0
  40. package/components/vertical-navigation/__examples__/icons.jsx +70 -0
  41. package/components/vertical-navigation/__examples__/notifications.jsx +66 -0
  42. package/components/vertical-navigation/component.json +8 -0
  43. package/components/vertical-navigation/private/item.d.ts +2 -0
  44. package/components/vertical-navigation/private/item.jsx +23 -1
  45. package/docs/PULL_REQUEST_TEMPLATE.md +1 -1
  46. package/lib/assets/styles/table.css +70 -0
  47. package/lib/components/builder-header/utilities.d.ts +20 -0
  48. package/lib/components/card/__docs__/__snapshots__/storybook-stories.storyshot +20 -5
  49. package/lib/components/combobox/__docs__/__snapshots__/storybook-stories.storyshot +178 -169
  50. package/lib/components/combobox/__tests__/combobox.browser-test.jsx +4 -5
  51. package/lib/components/combobox/combobox.js +27 -23
  52. package/lib/components/component-docs.json +160 -0
  53. package/lib/components/data-table/__docs__/__snapshots__/storybook-stories.storyshot +17997 -11862
  54. package/lib/components/data-table/__docs__/storybook-stories.jsx +5 -1
  55. package/lib/components/data-table/__examples__/advanced-single-select-fixed-header.jsx +1 -0
  56. package/lib/components/data-table/__examples__/basic-fluid-headless.jsx +105 -0
  57. package/lib/components/data-table/__examples__/interactive-elements.jsx +14 -0
  58. package/lib/components/data-table/__examples__/joined-with-page-header.jsx +11 -18
  59. package/lib/components/data-table/__examples__/resizable-columns.jsx +237 -0
  60. package/lib/components/data-table/__tests__/data-table.browser-test.jsx +133 -0
  61. package/lib/components/data-table/column.resizer.d.ts +1 -0
  62. package/lib/components/data-table/component.json +11 -7
  63. package/lib/components/data-table/index.js +444 -107
  64. package/lib/components/data-table/private/head.js +8 -3
  65. package/lib/components/data-table/private/header-cell.js +3 -1
  66. package/lib/components/data-table.d.ts +8 -0
  67. package/lib/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +17 -17
  68. package/lib/components/expression/__docs__/__snapshots__/storybook-stories.storyshot +90 -90
  69. package/lib/components/global-header/__docs__/__snapshots__/storybook-stories.storyshot +9 -9
  70. package/lib/components/index.d.ts +2 -0
  71. package/lib/components/menu-dropdown/__docs__/__snapshots__/storybook-stories.storyshot +552 -26
  72. package/lib/components/menu-dropdown/__docs__/storybook-stories.jsx +4 -16
  73. package/lib/components/menu-dropdown/__examples__/checkmark.jsx +48 -31
  74. package/lib/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +12 -7
  75. package/lib/components/modal/__tests__/modal.browser-test.jsx +4 -10
  76. package/lib/components/portal-settings/__docs__/__snapshots__/storybook-stories.storyshot +6 -6
  77. package/lib/components/progress-indicator/__docs__/__snapshots__/storybook-stories.storyshot +161 -14
  78. package/lib/components/progress-indicator/private/step-vertical.js +18 -4
  79. package/lib/components/setup-assistant/__docs__/__snapshots__/storybook-stories.storyshot +180 -13
  80. package/lib/components/site-stories.js +12 -3
  81. package/lib/components/utilities/menu-list/index.js +5 -2
  82. package/lib/components/utilities/menu-list/item.js +3 -2
  83. package/lib/components/vertical-navigation/__docs__/__snapshots__/storybook-stories.storyshot +326 -0
  84. package/lib/components/vertical-navigation/__docs__/storybook-stories.jsx +4 -0
  85. package/lib/components/vertical-navigation/__examples__/icons.jsx +70 -0
  86. package/lib/components/vertical-navigation/__examples__/notifications.jsx +66 -0
  87. package/lib/components/vertical-navigation/component.json +8 -0
  88. package/lib/components/vertical-navigation/private/item.d.ts +2 -0
  89. package/lib/components/vertical-navigation/private/item.js +5 -1
  90. package/lib/docs/PULL_REQUEST_TEMPLATE.md +1 -1
  91. package/lib/package.json +19 -6
  92. package/module/assets/styles/table.css +70 -0
  93. package/module/components/builder-header/utilities.d.ts +20 -0
  94. package/module/components/card/__docs__/__snapshots__/storybook-stories.storyshot +20 -5
  95. package/module/components/combobox/__docs__/__snapshots__/storybook-stories.storyshot +178 -169
  96. package/module/components/combobox/__tests__/combobox.browser-test.js +5 -6
  97. package/module/components/combobox/__tests__/combobox.browser-test.js.map +1 -1
  98. package/module/components/combobox/combobox.js +27 -23
  99. package/module/components/combobox/combobox.js.map +1 -1
  100. package/module/components/component-docs.json +160 -0
  101. package/module/components/data-table/__docs__/__snapshots__/storybook-stories.storyshot +17997 -11862
  102. package/module/components/data-table/__docs__/storybook-stories.js +6 -0
  103. package/module/components/data-table/__docs__/storybook-stories.js.map +1 -1
  104. package/module/components/data-table/__examples__/advanced-single-select-fixed-header.js +1 -0
  105. package/module/components/data-table/__examples__/advanced-single-select-fixed-header.js.map +1 -1
  106. package/module/components/data-table/__examples__/basic-fluid-headless.js +152 -0
  107. package/module/components/data-table/__examples__/basic-fluid-headless.js.map +1 -0
  108. package/module/components/data-table/__examples__/interactive-elements.js +9 -0
  109. package/module/components/data-table/__examples__/interactive-elements.js.map +1 -1
  110. package/module/components/data-table/__examples__/joined-with-page-header.js +9 -20
  111. package/module/components/data-table/__examples__/joined-with-page-header.js.map +1 -1
  112. package/module/components/data-table/__examples__/resizable-columns.js +266 -0
  113. package/module/components/data-table/__examples__/resizable-columns.js.map +1 -0
  114. package/module/components/data-table/__tests__/data-table.browser-test.js +99 -0
  115. package/module/components/data-table/__tests__/data-table.browser-test.js.map +1 -1
  116. package/module/components/data-table/column.resizer.d.ts +1 -0
  117. package/module/components/data-table/component.json +11 -7
  118. package/module/components/data-table/index.js +443 -107
  119. package/module/components/data-table/index.js.map +1 -1
  120. package/module/components/data-table/private/head.js +8 -3
  121. package/module/components/data-table/private/head.js.map +1 -1
  122. package/module/components/data-table/private/header-cell.js +3 -1
  123. package/module/components/data-table/private/header-cell.js.map +1 -1
  124. package/module/components/data-table.d.ts +8 -0
  125. package/module/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +17 -17
  126. package/module/components/expression/__docs__/__snapshots__/storybook-stories.storyshot +90 -90
  127. package/module/components/global-header/__docs__/__snapshots__/storybook-stories.storyshot +9 -9
  128. package/module/components/index.d.ts +2 -0
  129. package/module/components/menu-dropdown/__docs__/__snapshots__/storybook-stories.storyshot +552 -26
  130. package/module/components/menu-dropdown/__docs__/storybook-stories.js +9 -15
  131. package/module/components/menu-dropdown/__docs__/storybook-stories.js.map +1 -1
  132. package/module/components/menu-dropdown/__examples__/checkmark.js +53 -33
  133. package/module/components/menu-dropdown/__examples__/checkmark.js.map +1 -1
  134. package/module/components/menu-dropdown/__tests__/dropdown.browser-test.js +7 -4
  135. package/module/components/menu-dropdown/__tests__/dropdown.browser-test.js.map +1 -1
  136. package/module/components/modal/__tests__/modal.browser-test.js +4 -10
  137. package/module/components/modal/__tests__/modal.browser-test.js.map +1 -1
  138. package/module/components/portal-settings/__docs__/__snapshots__/storybook-stories.storyshot +6 -6
  139. package/module/components/progress-indicator/__docs__/__snapshots__/storybook-stories.storyshot +161 -14
  140. package/module/components/progress-indicator/private/step-vertical.js +18 -4
  141. package/module/components/progress-indicator/private/step-vertical.js.map +1 -1
  142. package/module/components/setup-assistant/__docs__/__snapshots__/storybook-stories.storyshot +180 -13
  143. package/module/components/site-stories.js +12 -3
  144. package/module/components/site-stories.js.map +1 -1
  145. package/module/components/utilities/menu-list/index.js +5 -2
  146. package/module/components/utilities/menu-list/index.js.map +1 -1
  147. package/module/components/utilities/menu-list/item.js +3 -2
  148. package/module/components/utilities/menu-list/item.js.map +1 -1
  149. package/module/components/vertical-navigation/__docs__/__snapshots__/storybook-stories.storyshot +326 -0
  150. package/module/components/vertical-navigation/__docs__/storybook-stories.js +10 -0
  151. package/module/components/vertical-navigation/__docs__/storybook-stories.js.map +1 -1
  152. package/module/components/vertical-navigation/__examples__/icons.js +149 -0
  153. package/module/components/vertical-navigation/__examples__/icons.js.map +1 -0
  154. package/module/components/vertical-navigation/__examples__/notifications.js +143 -0
  155. package/module/components/vertical-navigation/__examples__/notifications.js.map +1 -0
  156. package/module/components/vertical-navigation/component.json +8 -0
  157. package/module/components/vertical-navigation/private/item.d.ts +2 -0
  158. package/module/components/vertical-navigation/private/item.js +5 -1
  159. package/module/components/vertical-navigation/private/item.js.map +1 -1
  160. package/package.json +19 -6
  161. package/design-system-react-components.js +0 -62702
  162. package/design-system-react-components.js.map +0 -1
  163. package/design-system-react-components.min.js +0 -3
  164. package/design-system-react-components.min.js.LICENSE.txt +0 -83
  165. package/design-system-react-components.min.js.map +0 -1
  166. package/design-system-react.js +0 -73487
  167. package/design-system-react.js.map +0 -1
  168. package/design-system-react.min.js +0 -3
  169. package/design-system-react.min.js.LICENSE.txt +0 -83
  170. package/design-system-react.min.js.map +0 -1
  171. package/lib/design-system-react-components.min.js.LICENSE.txt +0 -83
  172. package/lib/design-system-react.min.js.LICENSE.txt +0 -83
@@ -19,6 +19,7 @@ import assign from 'lodash.assign';
19
19
  import reject from 'lodash.reject';
20
20
 
21
21
  // This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
22
+ import ColumnResizer from 'column-resizer';
22
23
  import checkProps from './check-props';
23
24
  import componentDoc from './component.json';
24
25
 
@@ -66,6 +67,11 @@ const defaultProps = {
66
67
  selection: [],
67
68
  hasMore: false,
68
69
  loadMoreOffset: 20,
70
+ resizable: false,
71
+ resizableOptions: {
72
+ resizeMode: 'fit',
73
+ draggingClass: 'slds-table-column-resizer',
74
+ },
69
75
  };
70
76
 
71
77
  /**
@@ -202,6 +208,10 @@ class DataTable extends React.Component {
202
208
  classNameRow: PropTypes.string,
203
209
  })
204
210
  ).isRequired,
211
+ /**
212
+ * Removes the header from the data table. Tested with snapshot testing
213
+ */
214
+ isHeadless: PropTypes.bool,
205
215
  /**
206
216
  * Makes DataTable joinable with PageHeader by adding appropriate classes/styling
207
217
  */
@@ -281,6 +291,19 @@ class DataTable extends React.Component {
281
291
  * A variant which removes horizontal padding. CSS class will be removed if `fixedLayout==true`.
282
292
  */
283
293
  unbufferedCell: PropTypes.bool,
294
+ /**
295
+ * A variant which allows column dividers to be grabbed with the mouse. This feature needs
296
+ * `@salesforce/design-system-react/assets/styles/table.css` to be loaded. This prop is in prototype` state. a) It may change within a minor release. (b) Web Content Accessibility Guidelines may not be met. (c) CSS imports may be required.
297
+ */
298
+ resizable: PropTypes.bool,
299
+ /**
300
+ * Object with properties to be used in case of resizable: true
301
+ *
302
+ * resizeMode: It is used to set how the resize method works. Those are the possible values: 'fit', 'flex' and 'overflow'
303
+ * onResize: Callback function to be fired when the user has ended dragging a column
304
+ * `@salesforce/design-system-react/assets/styles/table.css` to be loaded. This prop is in prototype` state. a) It may change within a minor release. (b) Web Content Accessibility Guidelines may not be met. (c) CSS imports may be required.
305
+ */
306
+ resizableOptions: PropTypes.object,
284
307
  };
285
308
 
286
309
  static defaultProps = defaultProps;
@@ -293,7 +316,9 @@ class DataTable extends React.Component {
293
316
  column: [],
294
317
  select: [],
295
318
  };
319
+ this.gripRefs = [];
296
320
  this.scrollerRef = null;
321
+ this.fixedHeaderContainer = {};
297
322
  this.state = {
298
323
  // Currently selected cell
299
324
  activeCell: {
@@ -324,14 +349,17 @@ class DataTable extends React.Component {
324
349
  }
325
350
 
326
351
  componentDidMount() {
327
- if (this.props.fixedHeader) {
352
+ if (this.getFixedHeader()) {
328
353
  this.toggleFixedHeaderListeners(true);
329
354
  this.resizeFixedHeaders();
330
355
  }
356
+ if (this.isResizable()) {
357
+ this.enableResize();
358
+ }
331
359
  }
332
360
 
333
361
  componentDidUpdate(prevProps, prevState) {
334
- if (this.props.fixedHeader) {
362
+ if (this.getFixedHeader()) {
335
363
  this.resizeFixedHeaders();
336
364
  // If the first page of results isn't enough to allow the user to scroll it causes
337
365
  // the user to get into a state where they cannot load the second page.
@@ -352,16 +380,55 @@ class DataTable extends React.Component {
352
380
  // eslint-disable-next-line react/no-did-update-set-state
353
381
  this.setState({ tableHasFocus: true });
354
382
  }
383
+ if (this.isResizable()) {
384
+ this.enableResize();
385
+ } else if (this.resizer) {
386
+ this.disableResize();
387
+ }
355
388
  }
356
389
 
357
390
  componentWillUnmount() {
358
391
  this.toggleFixedHeaderListeners(false);
392
+
393
+ if (this.isResizable()) {
394
+ this.disableResize();
395
+ }
396
+ }
397
+
398
+ onResize() {
399
+ const table = this.tableRef;
400
+ if (table) {
401
+ const columns = this.getFixedHeader()
402
+ ? table.getElementsByClassName('slds-cell-fixed')
403
+ : table.getElementsByTagName('th');
404
+ const columnsWidths = Array.from(columns).map(({ id, style }, index) => {
405
+ return {
406
+ id,
407
+ index,
408
+ width: parseInt(style.width, 10),
409
+ };
410
+ });
411
+ return columnsWidths;
412
+ }
413
+ return [];
359
414
  }
360
415
 
361
416
  getId() {
362
417
  return this.props.id || this.generatedId;
363
418
  }
364
419
 
420
+ getFixedHeader() {
421
+ return this.props.fixedHeader || this.props.resizable;
422
+ }
423
+
424
+ getKeyboardNavigation() {
425
+ return this.props.keyboardNavigation || this.props.resizable;
426
+ }
427
+
428
+ getFixedLayout() {
429
+ return this.props.fixedLayout || this.props.resizable;
430
+ }
431
+
365
432
  getFirstInteractiveElement(rowIndex, columnIndex) {
366
433
  if (
367
434
  this.state.mode === Mode.ACTIONABLE &&
@@ -426,6 +493,25 @@ class DataTable extends React.Component {
426
493
  }
427
494
  };
428
495
 
496
+ repositionResizers = () => {
497
+ const headers = [].concat(
498
+ this.headerRefs.select,
499
+ this.headerRefs.column,
500
+ this.headerRefs.action
501
+ );
502
+
503
+ if (this.gripRefs && this.tableRef) {
504
+ const tableOffset = this.tableRef.getBoundingClientRect();
505
+ this.gripRefs.forEach((grip, index) => {
506
+ const header = headers[index].getBoundingClientRect();
507
+ const relativeOffset = header.left - tableOffset.left;
508
+ const newPosition = relativeOffset + header.width;
509
+ // eslint-disable-next-line no-param-reassign
510
+ grip.style.left = `${newPosition}px`;
511
+ });
512
+ }
513
+ };
514
+
429
515
  resizeFixedHeaders = (event) => {
430
516
  const headerRefs = [].concat(
431
517
  this.headerRefs.select,
@@ -496,10 +582,81 @@ class DataTable extends React.Component {
496
582
  if (canUseEventListeners && this.scrollerRef) {
497
583
  this.scrollerRef[action]('scroll', this.resizeFixedHeaders);
498
584
  this.scrollerRef[action]('scroll', this.loadMoreIfNeeded);
585
+ this.scrollerRef[action]('scroll', this.repositionResizers);
499
586
  }
500
587
  }
501
588
  };
502
589
 
590
+ isResizable() {
591
+ return this.props.fixedLayout && this.props.resizable;
592
+ }
593
+
594
+ resizeGrips() {
595
+ const table = this.fixedHeaderContainer;
596
+
597
+ if (table) {
598
+ const grips = Array.from(table.getElementsByClassName('grip-handle'));
599
+
600
+ if (grips.length) {
601
+ this.gripRefs = grips;
602
+ this.gripRefs.forEach((grip) => {
603
+ // eslint-disable-next-line no-param-reassign
604
+ grip.style.height = `${parseInt(grip.style.height, 10) + 33}px`;
605
+ });
606
+ }
607
+ }
608
+ }
609
+
610
+ enableResize() {
611
+ if (canUseDOM) {
612
+ const remoteTable = this.tableRef;
613
+ const fixedHeader = this.getFixedHeader();
614
+ const disabledColumns = [];
615
+
616
+ if (this.props.selectRows) {
617
+ // eslint-disable-next-line fp/no-mutating-methods
618
+ disabledColumns.push(0);
619
+ }
620
+
621
+ if (!this.resizer) {
622
+ const options = {
623
+ ...defaultProps.resizableOptions,
624
+ ...{ disabledColumns },
625
+ ...this.props.resizableOptions,
626
+ };
627
+
628
+ const externalFunction = this.props.resizableOptions.onResize;
629
+ options.onResize = (e) => {
630
+ if (fixedHeader) {
631
+ this.resizeFixedHeaders(e);
632
+ this.repositionResizers();
633
+ }
634
+
635
+ const response = this.onResize();
636
+
637
+ if (externalFunction) externalFunction(response);
638
+ this.resizeGrips();
639
+ };
640
+
641
+ if (remoteTable) {
642
+ this.resizer = new ColumnResizer(remoteTable, options);
643
+ remoteTable.classList.remove('grip-padding');
644
+
645
+ if (fixedHeader) this.resizeFixedHeaders();
646
+
647
+ this.resizeGrips();
648
+ this.repositionResizers();
649
+ }
650
+ this.setState({}, () => this.state);
651
+ }
652
+ }
653
+ }
654
+
655
+ disableResize() {
656
+ if (this.resizer) this.resizer.reset({ disable: true });
657
+ this.gripRefs = [];
658
+ }
659
+
503
660
  changeActiveCell(rowIndex, columnIndex) {
504
661
  this.setState({
505
662
  tableHasFocus: true,
@@ -520,81 +677,145 @@ class DataTable extends React.Component {
520
677
  [KEYS.RIGHT]: { callback: (evt) => this.handleKeyDownRight(evt) },
521
678
  [KEYS.ENTER]: { callback: (evt) => this.handleKeyDownEnter(evt) },
522
679
  [KEYS.ESCAPE]: { callback: (evt) => this.handleKeyDownEscape(evt) },
680
+ [KEYS.TAB]:
681
+ this.state.mode === Mode.ACTIONABLE
682
+ ? { callback: (evt) => this.handleKeyTabPress(evt) }
683
+ : null,
523
684
  },
524
685
  });
525
686
  }
526
687
 
527
688
  handleKeyDownUp() {
528
- const newRowIndex = Math.max(this.state.activeCell.rowIndex - 1, 0);
529
- const activeElement = this.getFirstInteractiveElement(
530
- newRowIndex,
531
- this.state.activeCell.columnIndex
532
- );
533
- if (newRowIndex !== this.state.activeCell.rowIndex) {
534
- this.setState((prevState) => ({
535
- activeCell: {
536
- rowIndex: newRowIndex,
537
- columnIndex: prevState.activeCell.columnIndex,
538
- },
539
- activeElement,
540
- }));
689
+ if (
690
+ this.state.mode === Mode.NAVIGATION ||
691
+ this.state.activeCell.rowIndex > 0 ||
692
+ !this.isResizable()
693
+ ) {
694
+ const newRowIndex = Math.max(this.state.activeCell.rowIndex - 1, 0);
695
+ const activeElement = this.getFirstInteractiveElement(
696
+ newRowIndex,
697
+ this.state.activeCell.columnIndex
698
+ );
699
+ if (newRowIndex !== this.state.activeCell.rowIndex) {
700
+ this.setState((prevState) => ({
701
+ activeCell: {
702
+ rowIndex: newRowIndex,
703
+ columnIndex: prevState.activeCell.columnIndex,
704
+ },
705
+ activeElement,
706
+ }));
707
+
708
+ if (
709
+ this.state.mode === Mode.ACTIONABLE &&
710
+ newRowIndex === 0 &&
711
+ !activeElement
712
+ ) {
713
+ this.makeGripVisible(this.state.activeCell.columnIndex);
714
+ }
715
+ }
541
716
  }
542
717
  }
543
718
 
544
719
  handleKeyDownDown() {
545
- const newRowIndex = Math.min(
546
- this.state.activeCell.rowIndex + 1,
547
- this.props.items.length
548
- );
549
- const activeElement = this.getFirstInteractiveElement(
550
- newRowIndex,
551
- this.state.activeCell.columnIndex
552
- );
553
- if (newRowIndex !== this.state.activeCell.rowIndex) {
554
- this.setState((prevState) => ({
555
- activeCell: {
556
- rowIndex: newRowIndex,
557
- columnIndex: prevState.activeCell.columnIndex,
558
- },
559
- activeElement,
560
- }));
720
+ if (
721
+ this.state.mode === Mode.NAVIGATION ||
722
+ this.state.activeCell.rowIndex > 0 ||
723
+ !this.isResizable()
724
+ ) {
725
+ const newRowIndex = Math.min(
726
+ this.state.activeCell.rowIndex + 1,
727
+ this.props.items.length
728
+ );
729
+ const activeElement = this.getFirstInteractiveElement(
730
+ newRowIndex,
731
+ this.state.activeCell.columnIndex
732
+ );
733
+ if (newRowIndex !== this.state.activeCell.rowIndex) {
734
+ this.setState((prevState) => ({
735
+ activeCell: {
736
+ rowIndex: newRowIndex,
737
+ columnIndex: prevState.activeCell.columnIndex,
738
+ },
739
+ activeElement,
740
+ }));
741
+ }
561
742
  }
562
743
  }
563
744
 
745
+ displaceByArrowKey(factor) {
746
+ if (this.state.mode === Mode.ACTIONABLE) {
747
+ const { rowIndex, columnIndex } = this.state.activeCell;
748
+
749
+ if (rowIndex === 0) {
750
+ const table = this.tableRef;
751
+ const headers = table.getElementsByTagName('th');
752
+ headers[columnIndex].style.width = `${
753
+ parseInt(headers[columnIndex].style.width, 10) + factor
754
+ }px`;
755
+ this.resizeFixedHeaders();
756
+ this.repositionResizers();
757
+ this.resizeGrips();
758
+ }
759
+ }
760
+ }
761
+
762
+ makeGripVisible(newIndex) {
763
+ this.gripRefs.forEach((grip, index) => {
764
+ if (index === newIndex) grip.classList.add('grip-handle-active');
765
+ else grip.classList.remove('grip-handle-active');
766
+ });
767
+ }
768
+
564
769
  handleKeyDownLeft() {
565
- const newColumnIndex = Math.max(this.state.activeCell.columnIndex - 1, 0);
566
- const activeElement = this.getFirstInteractiveElement(
567
- this.state.activeCell.rowIndex,
568
- newColumnIndex
569
- );
570
- if (newColumnIndex !== this.state.activeCell.columnIndex) {
571
- this.setState((prevState) => ({
572
- activeCell: {
573
- rowIndex: prevState.activeCell.rowIndex,
574
- columnIndex: newColumnIndex,
575
- },
576
- activeElement,
577
- }));
770
+ if (
771
+ this.state.mode === Mode.NAVIGATION ||
772
+ this.state.activeCell.rowIndex > 0 ||
773
+ !this.isResizable()
774
+ ) {
775
+ const newColumnIndex = Math.max(this.state.activeCell.columnIndex - 1, 0);
776
+ const activeElement = this.getFirstInteractiveElement(
777
+ this.state.activeCell.rowIndex,
778
+ newColumnIndex
779
+ );
780
+ if (newColumnIndex !== this.state.activeCell.columnIndex) {
781
+ this.setState((prevState) => ({
782
+ activeCell: {
783
+ rowIndex: prevState.activeCell.rowIndex,
784
+ columnIndex: newColumnIndex,
785
+ },
786
+ activeElement,
787
+ }));
788
+ }
789
+ } else {
790
+ this.displaceByArrowKey(-10);
578
791
  }
579
792
  }
580
793
 
581
794
  handleKeyDownRight() {
582
- const newColumnIndex = Math.min(
583
- this.state.activeCell.columnIndex + 1,
584
- this.props.children.length - (this.props.selectRows ? 0 : 1)
585
- );
586
- const activeElement = this.getFirstInteractiveElement(
587
- this.state.activeCell.rowIndex,
588
- newColumnIndex
589
- );
590
- if (newColumnIndex !== this.state.activeCell.columnIndex) {
591
- this.setState((prevState) => ({
592
- activeCell: {
593
- rowIndex: prevState.activeCell.rowIndex,
594
- columnIndex: newColumnIndex,
595
- },
596
- activeElement,
597
- }));
795
+ if (
796
+ this.state.mode === Mode.NAVIGATION ||
797
+ this.state.activeCell.rowIndex > 0 ||
798
+ !this.isResizable()
799
+ ) {
800
+ const newColumnIndex = Math.min(
801
+ this.state.activeCell.columnIndex + 1,
802
+ this.props.children.length - (this.props.selectRows ? 0 : 1)
803
+ );
804
+ const activeElement = this.getFirstInteractiveElement(
805
+ this.state.activeCell.rowIndex,
806
+ newColumnIndex
807
+ );
808
+ if (newColumnIndex !== this.state.activeCell.columnIndex) {
809
+ this.setState((prevState) => ({
810
+ activeCell: {
811
+ rowIndex: prevState.activeCell.rowIndex,
812
+ columnIndex: newColumnIndex,
813
+ },
814
+ activeElement,
815
+ }));
816
+ }
817
+ } else {
818
+ this.displaceByArrowKey(10);
598
819
  }
599
820
  }
600
821
 
@@ -612,6 +833,10 @@ class DataTable extends React.Component {
612
833
  mode: Mode.ACTIONABLE,
613
834
  activeElement,
614
835
  });
836
+
837
+ if (rowIndex === 0 && !activeElement) {
838
+ this.makeGripVisible(columnIndex);
839
+ }
615
840
  }
616
841
  }
617
842
 
@@ -621,6 +846,115 @@ class DataTable extends React.Component {
621
846
  mode: Mode.NAVIGATION,
622
847
  activeElement: null,
623
848
  });
849
+ this.makeGripVisible(null);
850
+ }
851
+ }
852
+
853
+ moveNext(event, rowIndex, columnIndex) {
854
+ const headers = [].concat(
855
+ this.headerRefs.select,
856
+ this.headerRefs.column,
857
+ this.headerRefs.action
858
+ );
859
+ let newRowIndex = 0;
860
+ let newColumnIndex = 0;
861
+
862
+ if (event.shiftKey) {
863
+ if (columnIndex - 1 >= 0) {
864
+ newColumnIndex = columnIndex - 1;
865
+ newRowIndex = rowIndex;
866
+ } else {
867
+ if (rowIndex > 0) newRowIndex = rowIndex - 1;
868
+ else newRowIndex = this.props.items.length;
869
+
870
+ newColumnIndex = headers.length - 1;
871
+ }
872
+ } else if (columnIndex + 1 < headers.length) {
873
+ newColumnIndex = columnIndex + 1;
874
+ newRowIndex = rowIndex;
875
+ } else {
876
+ if (rowIndex < this.props.items.length) newRowIndex = rowIndex + 1;
877
+ else newRowIndex = 0;
878
+
879
+ newColumnIndex = 0;
880
+ }
881
+
882
+ this.changeActiveCell(newRowIndex, newColumnIndex);
883
+ }
884
+
885
+ handleNextActionable(event) {
886
+ const { rowIndex, columnIndex } = this.state.activeCell;
887
+ const currentActiveElement = this.state.activeElement;
888
+ const rowActiveElements =
889
+ this.interactiveElements[rowIndex] &&
890
+ this.interactiveElements[rowIndex][columnIndex]
891
+ ? this.interactiveElements[rowIndex][columnIndex]
892
+ : null;
893
+
894
+ if (rowActiveElements) {
895
+ if (currentActiveElement) {
896
+ const index = rowActiveElements.indexOf(currentActiveElement);
897
+
898
+ if (event.shiftKey) {
899
+ return index > 0 ? rowActiveElements[index - 1] : null;
900
+ }
901
+ return index < rowActiveElements.length - 1
902
+ ? rowActiveElements[index + 1]
903
+ : null;
904
+ }
905
+ return !event.shiftKey
906
+ ? rowActiveElements[0]
907
+ : rowActiveElements[rowActiveElements.length - 1];
908
+ }
909
+ return null;
910
+ }
911
+
912
+ handleKeyTabPress(event) {
913
+ const { rowIndex, columnIndex } = this.state.activeCell;
914
+
915
+ if (this.state.mode === Mode.ACTIONABLE) {
916
+ const nextActionable = this.handleNextActionable(event);
917
+
918
+ if (nextActionable) {
919
+ this.setState({ activeElement: nextActionable });
920
+ if (this.isResizable()) this.makeGripVisible(null);
921
+ } else if (rowIndex === 0) {
922
+ const headers = [].concat(
923
+ this.headerRefs.select,
924
+ this.headerRefs.column,
925
+ this.headerRefs.action
926
+ );
927
+ let newIndex = 0;
928
+
929
+ if (!event.shiftKey)
930
+ newIndex = columnIndex + 1 < headers.length ? columnIndex + 1 : 0;
931
+ else
932
+ newIndex =
933
+ columnIndex - 1 >= 0 ? columnIndex - 1 : headers.length - 1;
934
+ this.setState({
935
+ mode: Mode.ACTIONABLE,
936
+ activeElement: null,
937
+ });
938
+
939
+ // eslint-disable-next-line no-param-reassign
940
+ headers.forEach((header, index) => {
941
+ if (index === newIndex) {
942
+ // eslint-disable-next-line no-param-reassign
943
+ header.tabIndex = 0;
944
+ // eslint-disable-next-line no-param-reassign
945
+ header.focus();
946
+ // eslint-disable-next-line no-param-reassign
947
+ } else header.tabIndex = -1;
948
+ });
949
+
950
+ if (this.isResizable()) this.makeGripVisible(newIndex);
951
+ } else {
952
+ this.moveNext(event, rowIndex, columnIndex);
953
+ this.setState({
954
+ mode: Mode.ACTIONABLE,
955
+ activeElement: null,
956
+ });
957
+ }
624
958
  }
625
959
  }
626
960
 
@@ -630,10 +964,13 @@ class DataTable extends React.Component {
630
964
  }
631
965
  const existingElements =
632
966
  this.interactiveElements[rowIndex][columnIndex] || [];
633
- this.interactiveElements[rowIndex][columnIndex] = [
634
- ...existingElements,
635
- elementId,
636
- ];
967
+
968
+ if (!existingElements.includes(elementId)) {
969
+ this.interactiveElements[rowIndex][columnIndex] = [
970
+ ...existingElements,
971
+ elementId,
972
+ ];
973
+ }
637
974
  }
638
975
 
639
976
  // ### Render
@@ -684,7 +1021,7 @@ class DataTable extends React.Component {
684
1021
  ) {
685
1022
  const { dropdown } = child.props;
686
1023
  const dropdownPropOverrides = {};
687
- if (this.props.fixedHeader) {
1024
+ if (this.getFixedHeader()) {
688
1025
  dropdownPropOverrides.menuPosition = 'overflowBoundaryElement';
689
1026
  }
690
1027
  RowActions = React.cloneElement(child, {
@@ -740,7 +1077,7 @@ class DataTable extends React.Component {
740
1077
  registerInteractiveElement: this.registerInteractiveElement,
741
1078
  allowKeyboardNavigation: this.state.allowKeyboardNavigation,
742
1079
  setAllowKeyboardNavigation: (allowKeyboardNavigation) => {
743
- if (this.props.keyboardNavigation) {
1080
+ if (this.getKeyboardNavigation()) {
744
1081
  this.setState({ allowKeyboardNavigation });
745
1082
  }
746
1083
  },
@@ -754,18 +1091,19 @@ class DataTable extends React.Component {
754
1091
  className={classNames(
755
1092
  'slds-table',
756
1093
  {
757
- 'slds-table_fixed-layout': this.props.fixedLayout,
758
- 'slds-table_header-fixed': this.props.fixedHeader,
759
- 'slds-table_resizable-cols': this.props.fixedLayout,
1094
+ 'slds-table_fixed-layout': this.getFixedLayout(),
1095
+ 'slds-table_header-fixed': this.getFixedHeader(),
1096
+ 'slds-table_resizable-cols': this.getFixedLayout(),
760
1097
  'slds-table_bordered': !this.props.unborderedRow,
761
1098
  'slds-table_cell-buffer':
762
- !this.props.fixedLayout && !this.props.unbufferedCell,
1099
+ !this.getFixedLayout() && !this.props.unbufferedCell,
763
1100
  'slds-max-medium-table_stacked': this.props.stacked,
764
1101
  'slds-max-medium-table_stacked-horizontal': this.props
765
1102
  .stackedHorizontal,
766
1103
  'slds-table_striped': this.props.striped,
767
1104
  'slds-table_col-bordered': this.props.columnBordered,
768
1105
  'slds-no-row-hover': this.props.noRowHover,
1106
+ 'slds-table_header-hidden': this.props.isHeadless,
769
1107
  },
770
1108
  this.props.className
771
1109
  )}
@@ -775,7 +1113,7 @@ class DataTable extends React.Component {
775
1113
  this.tableRef = node;
776
1114
  }
777
1115
  }}
778
- role={this.props.fixedLayout ? 'grid' : null}
1116
+ role={this.getFixedLayout() ? 'grid' : null}
779
1117
  onBlur={(event) => {
780
1118
  if (
781
1119
  this.tableRef &&
@@ -786,6 +1124,7 @@ class DataTable extends React.Component {
786
1124
  mode: Mode.NAVIGATION,
787
1125
  activeElement: null,
788
1126
  });
1127
+ this.makeGripVisible(null);
789
1128
  }
790
1129
  }}
791
1130
  style={this.props.style}
@@ -793,8 +1132,8 @@ class DataTable extends React.Component {
793
1132
  <DataTableHead
794
1133
  assistiveText={assistiveText}
795
1134
  allSelected={allSelected}
796
- fixedHeader={this.props.fixedHeader}
797
- fixedLayout={this.props.fixedLayout}
1135
+ fixedHeader={this.getFixedHeader()}
1136
+ fixedLayout={this.getFixedLayout()}
798
1137
  headerRefs={(ref, index) => {
799
1138
  if (index === 'action' || index === 'select') {
800
1139
  if (ref) {
@@ -806,6 +1145,7 @@ class DataTable extends React.Component {
806
1145
  this.headerRefs.column[index] = ref;
807
1146
  }
808
1147
  }}
1148
+ isHidden={this.props.isHeadless}
809
1149
  indeterminateSelected={indeterminateSelected}
810
1150
  canSelectRows={canSelectRows}
811
1151
  columns={columns}
@@ -838,7 +1178,7 @@ class DataTable extends React.Component {
838
1178
  canSelectRows={canSelectRows}
839
1179
  className={item.classNameRow}
840
1180
  columns={columns}
841
- fixedLayout={this.props.fixedLayout}
1181
+ fixedLayout={this.getFixedLayout()}
842
1182
  id={rowId}
843
1183
  index={index}
844
1184
  item={item}
@@ -856,7 +1196,7 @@ class DataTable extends React.Component {
856
1196
  </tbody>
857
1197
  </table>
858
1198
  </TableContext.Provider>
859
- {this.props.fixedHeader && this.props.hasMore && (
1199
+ {this.getFixedHeader() && this.props.hasMore && (
860
1200
  <div className="slds-is-relative slds-p-around_large">
861
1201
  <Spinner
862
1202
  assistiveText={{ label: this.props.assistiveText.loadingMore }}
@@ -869,7 +1209,7 @@ class DataTable extends React.Component {
869
1209
  </React.Fragment>
870
1210
  );
871
1211
 
872
- if (this.props.fixedHeader) {
1212
+ if (this.getFixedHeader()) {
873
1213
  const border = `1px solid ${colorGray5}`;
874
1214
  const styles = {
875
1215
  borderTop: border,
@@ -884,9 +1224,23 @@ class DataTable extends React.Component {
884
1224
  styles.borderRadius = tableBorderRadius;
885
1225
  }
886
1226
 
1227
+ const fixedScrollerStyle = {
1228
+ height: '100%',
1229
+ };
1230
+
1231
+ if (this.props.resizable) {
1232
+ fixedScrollerStyle.overflowY = 'auto';
1233
+ fixedScrollerStyle.overflowX = 'hidden';
1234
+ } else {
1235
+ fixedScrollerStyle.overflow = 'auto';
1236
+ }
1237
+
887
1238
  component = (
888
1239
  <div
889
1240
  className="slds-table_header-fixed_container"
1241
+ ref={(ref) => {
1242
+ this.fixedHeaderContainer = ref;
1243
+ }}
890
1244
  style={styles}
891
1245
  onScroll={(e) => {
892
1246
  const containerScrollLeft = e.target.scrollLeft;
@@ -904,10 +1258,7 @@ class DataTable extends React.Component {
904
1258
  ref={(ref) => {
905
1259
  this.scrollerRef = ref;
906
1260
  }}
907
- style={{
908
- height: '100%',
909
- overflow: 'auto',
910
- }}
1261
+ style={fixedScrollerStyle}
911
1262
  >
912
1263
  {component}
913
1264
  </div>