@onehat/ui 0.3.256 → 0.3.258

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.256",
3
+ "version": "0.3.258",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -87,6 +87,7 @@ export function ComboComponent(props) {
87
87
  [isRendered, setIsRendered] = useState(false),
88
88
  [isReady, setIsReady] = useState(false),
89
89
  [isSearchMode, setIsSearchMode] = useState(false),
90
+ [isNavigatingViaKeyboard, setIsNavigatingViaKeyboard] = useState(false),
90
91
  [containerWidth, setContainerWidth] = useState(),
91
92
  [gridSelection, setGridSelection] = useState(null),
92
93
  [textInputValue, setTextInputValue] = useState(''),
@@ -150,6 +151,12 @@ export function ComboComponent(props) {
150
151
  toggleMenu = () => {
151
152
  setIsMenuShown(!isMenuShown);
152
153
  },
154
+ temporarilySetIsNavigatingViaKeyboard = () => {
155
+ setIsNavigatingViaKeyboard(true);
156
+ setTimeout(() => {
157
+ setIsNavigatingViaKeyboard(false);
158
+ }, 1000);
159
+ },
153
160
  getDisplayValue = () => {
154
161
  return displayValueRef.current;
155
162
  },
@@ -212,6 +219,7 @@ export function ComboComponent(props) {
212
219
  }
213
220
  switch(e.key) {
214
221
  case 'Escape':
222
+ e.preventDefault();
215
223
  setIsSearchMode(false);
216
224
  resetTextInputValue();
217
225
  hideMenu();
@@ -231,32 +239,29 @@ export function ComboComponent(props) {
231
239
  return;
232
240
  }
233
241
 
234
- doIt();
235
-
236
- function doIt() {
237
- setValue(gridSelection?.id);
238
- hideMenu();
242
+ let id = null;
243
+ if (gridSelection.length && gridSelection[0].id) {
244
+ id = gridSelection[0].id;
239
245
  }
246
+ setValue(id);
247
+ hideMenu();
248
+ break;
249
+ case 'ArrowDown':
250
+ e.preventDefault();
251
+ showMenu();
252
+ temporarilySetIsNavigatingViaKeyboard();
253
+ setTimeout(() => {
254
+ self.children.grid.selectNext();
255
+ }, 10);
256
+ break;
257
+ case 'ArrowUp':
258
+ e.preventDefault();
259
+ showMenu();
260
+ temporarilySetIsNavigatingViaKeyboard();
261
+ setTimeout(() => {
262
+ self.children.grid.selectPrev();
263
+ }, 10);
240
264
  break;
241
- // case 'ArrowDown':
242
- // e.preventDefault();
243
- // showMenu();
244
- // selectNext();
245
- // setTimeout(() => {
246
- // if (!self.children?.grid?.selectPrev) {
247
- // debugger;
248
- // }
249
- // self.children.grid.selectNext();
250
- // }, 10);
251
- // break;
252
- // case 'ArrowUp':
253
- // e.preventDefault();
254
- // showMenu();
255
- // selectPrev();
256
- // setTimeout(() => {
257
- // self.children.grid.selectPrev();
258
- // }, 10);
259
- // break;
260
265
  default:
261
266
  }
262
267
  },
@@ -715,7 +720,7 @@ export function ComboComponent(props) {
715
720
  if (selection[0]?.id === value) {
716
721
  setIsSearchMode(false);
717
722
  resetTextInputValue();
718
- if (hideMenuOnSelection && !isEditor) {
723
+ if (hideMenuOnSelection && !isNavigatingViaKeyboard && !isEditor) {
719
724
  hideMenu();
720
725
  }
721
726
  return;
@@ -734,7 +739,7 @@ export function ComboComponent(props) {
734
739
  if (selection[0] && selection[0][idIx] === value) {
735
740
  setIsSearchMode(false);
736
741
  resetTextInputValue();
737
- if (hideMenuOnSelection) {
742
+ if (hideMenuOnSelection && !isNavigatingViaKeyboard) {
738
743
  hideMenu();
739
744
  }
740
745
  return;
@@ -748,7 +753,7 @@ export function ComboComponent(props) {
748
753
  return;
749
754
  }
750
755
 
751
- if (hideMenuOnSelection && !isEditor) {
756
+ if (hideMenuOnSelection && !isNavigatingViaKeyboard && !isEditor) {
752
757
  hideMenu();
753
758
  }
754
759
 
@@ -172,6 +172,10 @@ function GridComponent(props) {
172
172
  selectRangeTo,
173
173
  isInSelection,
174
174
  noSelectorMeansNoResults = false,
175
+ selectNext,
176
+ selectPrev,
177
+ addNextToSelection,
178
+ addPrevToSelection,
175
179
 
176
180
  // DataMgt
177
181
  selectorId,
@@ -238,8 +242,7 @@ function GridComponent(props) {
238
242
  if (disableWithSelection) {
239
243
  return;
240
244
  }
241
- const
242
- {
245
+ const {
243
246
  shiftKey = false,
244
247
  metaKey = false,
245
248
  } = e;
@@ -719,6 +722,51 @@ function GridComponent(props) {
719
722
  id = noSelectorMeansNoResults ? 'NO_MATCHES' : null;
720
723
  }
721
724
  Repository.filter(selectorId, id, false); // so it doesn't clear existing filters
725
+ },
726
+ onGridKeyDown = (e) => {
727
+ if (isInlineEditorShown) {
728
+ return;
729
+ }
730
+ if (disableWithSelection) {
731
+ return;
732
+ }
733
+ const {
734
+ shiftKey = false,
735
+ } = e;
736
+ if (selectionMode === SELECTION_MODE_MULTI && shiftKey) {
737
+ switch(e.key) {
738
+ case 'ArrowDown':
739
+ e.preventDefault();
740
+ addNextToSelection();
741
+ break;
742
+ case 'ArrowUp':
743
+ e.preventDefault();
744
+ addPrevToSelection();
745
+ break;
746
+ }
747
+ } else {
748
+ // selectionMode is SELECTION_MODE_SINGLE
749
+ switch(e.key) {
750
+ case 'Enter':
751
+ // NOTE: This is never being reached.
752
+ // The event is getting captured somwhere else,
753
+ // but I can't find where.
754
+ // e.preventDefault();
755
+
756
+ // launch inline or windowed editor
757
+ // const p = props;
758
+ // debugger;
759
+ break;
760
+ case 'ArrowDown':
761
+ e.preventDefault();
762
+ selectNext();
763
+ break;
764
+ case 'ArrowUp':
765
+ e.preventDefault();
766
+ selectPrev();
767
+ break;
768
+ }
769
+ }
722
770
  };
723
771
 
724
772
  useEffect(() => {
@@ -771,41 +819,18 @@ function GridComponent(props) {
771
819
  return;
772
820
  }
773
821
 
774
- // destructure so we can set defaults
775
- const {
776
- header,
777
- fieldName, // from @onehat/data model
778
- type, // specify which column type to use (custom or built-in)
779
- isEditable = false,
780
- editor,
781
- format,
782
- renderer, // React component will render the output
783
- reorderable = true,
784
- resizable = true,
785
- sortable = true,
786
- w,
787
- flex,
788
- isHidden = false,
789
- } = columnConfig,
790
-
791
- config = {
822
+ const
823
+ defaults = {
792
824
  columnId: uuid(),
793
- header,
794
- fieldName,
795
- type,
796
- isEditable,
797
- editor,
798
- format,
799
- renderer,
800
- reorderable,
801
- resizable,
802
- sortable,
803
- w,
804
- flex,
805
- isHidden,
825
+ isEditable: false,
826
+ reorderable: true,
827
+ resizable: true,
828
+ sortable: true,
829
+ isHidden: false,
806
830
  isOver: false,
807
- };
808
-
831
+ },
832
+ config = _.assign({}, defaults, columnConfig);
833
+
809
834
  if (!(config.w || config.width) && !config.flex) {
810
835
  // Neither is set
811
836
  config.w = 100; // default
@@ -1038,6 +1063,8 @@ function GridComponent(props) {
1038
1063
  {...testProps('Grid')}
1039
1064
  testID="outerContainer"
1040
1065
  ref={containerRef}
1066
+ tabIndex={0}
1067
+ onKeyDown={onGridKeyDown}
1041
1068
  w="100%"
1042
1069
  bg={bg}
1043
1070
  borderWidth={styles.GRID_BORDER_WIDTH}
@@ -64,13 +64,19 @@ export default function withSelection(WrappedComponent) {
64
64
  fireEvent('secondaryChangeSelection', secondarySelection);
65
65
  }
66
66
  },
67
+ secondarySelectPrev = () => {
68
+ secondarySelectDirection(SELECT_UP);
69
+ },
67
70
  secondarySelectNext = () => {
68
71
  secondarySelectDirection(SELECT_DOWN);
69
72
  },
70
- secondarySelectPrev = () => {
71
- secondarySelectDirection(SELECT_UP);
73
+ secondaryAddPrevToSelection = () => {
74
+ secondarySelectDirection(SELECT_UP, true);
75
+ },
76
+ secondaryAddNextToSelection = () => {
77
+ secondarySelectDirection(SELECT_DOWN, true);
72
78
  },
73
- secondarySelectDirection = (which) => {
79
+ secondarySelectDirection = (which, isAdd = false) => {
74
80
  const { items, max, min, noSelection, } = getMaxMinSelectionIndices();
75
81
  let newIx;
76
82
  if (which === SELECT_DOWN) {
@@ -89,12 +95,15 @@ export default function withSelection(WrappedComponent) {
89
95
  }
90
96
  }
91
97
  if (items[newIx]) {
92
- secondarySetSelection([items[newIx]]);
98
+ if (isAdd) {
99
+ secondaryAddToSelection(items[newIx]);
100
+ } else {
101
+ secondarySetSelection([items[newIx]]);
102
+ }
93
103
  }
94
104
  },
95
105
  secondaryAddToSelection = (item) => {
96
- let newSelection = [];
97
- newSelection = _.clone(secondaryLocalSelection); // so we get a new object, so descendants rerender
106
+ const newSelection = _.clone(secondaryLocalSelection); // so we get a new object, so descendants rerender
98
107
  newSelection.push(item);
99
108
  secondarySetSelection(newSelection);
100
109
  },
@@ -347,8 +356,10 @@ export default function withSelection(WrappedComponent) {
347
356
  if (self) {
348
357
  self.secondarySelection = secondaryLocalSelection;
349
358
  self.secondarySetSelection = secondarySetSelection;
350
- self.secondarySelectNext = secondarySelectNext;
351
359
  self.secondarySelectPrev = secondarySelectPrev;
360
+ self.secondarySelectNext = secondarySelectNext;
361
+ self.secondaryAddPrevToSelection = secondaryAddPrevToSelection;
362
+ self.secondaryAddNextToSelection = secondaryAddNextToSelection;
352
363
  self.secondaryAddToSelection = secondaryAddToSelection;
353
364
  self.secondaryRemoveFromSelection = secondaryRemoveFromSelection;
354
365
  self.secondaryDeselectAll = secondaryDeselectAll;
@@ -388,8 +399,10 @@ export default function withSelection(WrappedComponent) {
388
399
  secondarySelection={secondaryLocalSelection}
389
400
  secondarySetSelection={secondarySetSelection}
390
401
  secondarySelectionMode={secondarySelectionMode}
391
- secondarySelectNext={secondarySelectNext}
392
402
  secondarySelectPrev={secondarySelectPrev}
403
+ secondarySelectNext={secondarySelectNext}
404
+ secondaryAddNextToSelection={secondaryAddNextToSelection}
405
+ secondaryAddPrevToSelection={secondaryAddPrevToSelection}
393
406
  secondaryRemoveFromSelection={secondaryRemoveFromSelection}
394
407
  secondaryAddToSelection={secondaryAddToSelection}
395
408
  secondaryDeselectAll={secondaryDeselectAll}
@@ -64,13 +64,19 @@ export default function withSelection(WrappedComponent) {
64
64
  }
65
65
  forceUpdate();
66
66
  },
67
+ selectPrev = () => {
68
+ selectDirection(SELECT_UP);
69
+ },
67
70
  selectNext = () => {
68
71
  selectDirection(SELECT_DOWN);
69
72
  },
70
- selectPrev = () => {
71
- selectDirection(SELECT_UP);
73
+ addPrevToSelection = () => {
74
+ selectDirection(SELECT_UP, true);
75
+ },
76
+ addNextToSelection = () => {
77
+ selectDirection(SELECT_DOWN, true);
72
78
  },
73
- selectDirection = (which) => {
79
+ selectDirection = (which, isAdd = false) => {
74
80
  const { items, max, min, noSelection, } = getMaxMinSelectionIndices();
75
81
  let newIx;
76
82
  if (which === SELECT_DOWN) {
@@ -89,12 +95,15 @@ export default function withSelection(WrappedComponent) {
89
95
  }
90
96
  }
91
97
  if (items[newIx]) {
92
- setSelection([items[newIx]]);
98
+ if (isAdd) {
99
+ addToSelection(items[newIx]);
100
+ } else {
101
+ setSelection([items[newIx]]);
102
+ }
93
103
  }
94
104
  },
95
105
  addToSelection = (item) => {
96
- let newSelection = [];
97
- newSelection = _.clone(localSelection.current); // so we get a new object, so descendants rerender
106
+ const newSelection = _.clone(localSelection.current); // so we get a new object, so descendants rerender
98
107
  newSelection.push(item);
99
108
  setSelection(newSelection);
100
109
  },
@@ -345,8 +354,10 @@ export default function withSelection(WrappedComponent) {
345
354
  if (self) {
346
355
  self.selection = localSelection.current;
347
356
  self.setSelection = setSelection;
348
- self.selectNext = selectNext;
349
357
  self.selectPrev = selectPrev;
358
+ self.selectNext = selectNext;
359
+ self.addPrevToSelection = addPrevToSelection;
360
+ self.addNextToSelection = addNextToSelection;
350
361
  self.addToSelection = addToSelection;
351
362
  self.removeFromSelection = removeFromSelection;
352
363
  self.deselectAll = deselectAll;
@@ -386,8 +397,10 @@ export default function withSelection(WrappedComponent) {
386
397
  selection={localSelection.current}
387
398
  setSelection={setSelection}
388
399
  selectionMode={selectionMode}
389
- selectNext={selectNext}
390
400
  selectPrev={selectPrev}
401
+ selectNext={selectNext}
402
+ addNextToSelection={addNextToSelection}
403
+ addPrevToSelection={addPrevToSelection}
391
404
  removeFromSelection={removeFromSelection}
392
405
  addToSelection={addToSelection}
393
406
  deselectAll={deselectAll}