orc-shared 5.10.2-dev.2 → 5.10.2-dev.4

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.
@@ -286,6 +286,9 @@ var InputBase = function InputBase(_ref) {
286
286
  setInputText(_currentValue2.toString());
287
287
  }
288
288
  };
289
+ var focusInput = function focusInput(target) {
290
+ target.closest(".InputBase-input-wrapper").getElementsByTagName("input")[0].focus();
291
+ };
289
292
  controlSpecificSuffix = /*#__PURE__*/_react.default.createElement("div", {
290
293
  className: classes.numericSpinnerContainer
291
294
  }, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
@@ -293,8 +296,15 @@ var InputBase = function InputBase(_ref) {
293
296
  tabIndex: "-1",
294
297
  "data-qa": "increase",
295
298
  disabled: disabled,
296
- onClick: function onClick() {
297
- return increaseNumericValue();
299
+ onMouseDown: function onMouseDown(event) {
300
+ return event.preventDefault();
301
+ } // prevent the button from stealing focus
302
+ ,
303
+ onClick: function onClick(event) {
304
+ event.preventDefault();
305
+ event.stopPropagation();
306
+ increaseNumericValue();
307
+ focusInput(event.target);
298
308
  }
299
309
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
300
310
  id: "chevron-up"
@@ -303,8 +313,15 @@ var InputBase = function InputBase(_ref) {
303
313
  tabIndex: "-1",
304
314
  "data-qa": "decrease",
305
315
  disabled: disabled,
306
- onClick: function onClick() {
307
- return decreaseNumericValue();
316
+ onMouseDown: function onMouseDown(event) {
317
+ return event.preventDefault();
318
+ } // prevent the button from stealing focus
319
+ ,
320
+ onClick: function onClick(event) {
321
+ event.preventDefault();
322
+ event.stopPropagation();
323
+ decreaseNumericValue();
324
+ focusInput(event.target);
308
325
  }
309
326
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
310
327
  id: "chevron-down"
@@ -328,6 +345,7 @@ var InputBase = function InputBase(_ref) {
328
345
  } else {
329
346
  decreaseNumericValue();
330
347
  }
348
+ focusInput(event.target);
331
349
  };
332
350
  }
333
351
  }
@@ -402,6 +420,19 @@ var InputBase = function InputBase(_ref) {
402
420
 
403
421
  // eslint-disable-next-line react-hooks/exhaustive-deps
404
422
  }, [inputText, metadata, timeoutDelay, update, value]);
423
+ if (onKeyDown) {
424
+ if (inputAttributes.onKeyDown) {
425
+ var originalKeyDown = inputAttributes.onKeyDown;
426
+ inputAttributes.onKeyDown = function (event) {
427
+ originalKeyDown(event);
428
+ if (!event.isDefaultPrevented()) {
429
+ onKeyDown(event);
430
+ }
431
+ };
432
+ } else {
433
+ inputAttributes.onKeyDown = onKeyDown;
434
+ }
435
+ }
405
436
  return /*#__PURE__*/_react.default.createElement("div", {
406
437
  className: classes.container
407
438
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -411,7 +442,8 @@ var InputBase = function InputBase(_ref) {
411
442
  }, label), /*#__PURE__*/_react.default.createElement("div", {
412
443
  style: {
413
444
  display: "flex"
414
- }
445
+ },
446
+ className: "InputBase-input-wrapper"
415
447
  }, /*#__PURE__*/_react.default.createElement(_InputBase.default, {
416
448
  classes: {
417
449
  input: (0, _classnames.default)(classes.controlInput, inputBaseInputStyle),
@@ -426,7 +458,6 @@ var InputBase = function InputBase(_ref) {
426
458
  placeholder: placeholder,
427
459
  value: textToDisplay,
428
460
  fullWidth: true,
429
- onKeyDown: onKeyDown,
430
461
  onWheel: onWheel,
431
462
  onChange: function onChange(event) {
432
463
  return onChangeHandler(event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "5.10.2-dev.2",
3
+ "version": "5.10.2-dev.4",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -258,6 +258,10 @@ const InputBase = ({ inputProps }) => {
258
258
  }
259
259
  };
260
260
 
261
+ const focusInput = target => {
262
+ target.closest(".InputBase-input-wrapper").getElementsByTagName("input")[0].focus();
263
+ };
264
+
261
265
  controlSpecificSuffix = (
262
266
  <div className={classes.numericSpinnerContainer}>
263
267
  <IconButton
@@ -265,7 +269,13 @@ const InputBase = ({ inputProps }) => {
265
269
  tabIndex="-1"
266
270
  data-qa="increase"
267
271
  disabled={disabled}
268
- onClick={() => increaseNumericValue()}
272
+ onMouseDown={event => event.preventDefault()} // prevent the button from stealing focus
273
+ onClick={event => {
274
+ event.preventDefault();
275
+ event.stopPropagation();
276
+ increaseNumericValue();
277
+ focusInput(event.target);
278
+ }}
269
279
  >
270
280
  <Icon id="chevron-up" />
271
281
  </IconButton>
@@ -275,7 +285,13 @@ const InputBase = ({ inputProps }) => {
275
285
  tabIndex="-1"
276
286
  data-qa="decrease"
277
287
  disabled={disabled}
278
- onClick={() => decreaseNumericValue()}
288
+ onMouseDown={event => event.preventDefault()} // prevent the button from stealing focus
289
+ onClick={event => {
290
+ event.preventDefault();
291
+ event.stopPropagation();
292
+ decreaseNumericValue();
293
+ focusInput(event.target);
294
+ }}
279
295
  >
280
296
  <Icon id="chevron-down" />
281
297
  </IconButton>
@@ -304,6 +320,8 @@ const InputBase = ({ inputProps }) => {
304
320
  } else {
305
321
  decreaseNumericValue();
306
322
  }
323
+
324
+ focusInput(event.target);
307
325
  };
308
326
  }
309
327
  }
@@ -395,11 +413,26 @@ const InputBase = ({ inputProps }) => {
395
413
  // eslint-disable-next-line react-hooks/exhaustive-deps
396
414
  }, [inputText, metadata, timeoutDelay, update, value]);
397
415
 
416
+ if (onKeyDown) {
417
+ if (inputAttributes.onKeyDown) {
418
+ const originalKeyDown = inputAttributes.onKeyDown;
419
+ inputAttributes.onKeyDown = event => {
420
+ originalKeyDown(event);
421
+
422
+ if (!event.isDefaultPrevented()) {
423
+ onKeyDown(event);
424
+ }
425
+ };
426
+ } else {
427
+ inputAttributes.onKeyDown = onKeyDown;
428
+ }
429
+ }
430
+
398
431
  return (
399
432
  <div className={classes.container}>
400
433
  <div className={classes.inputContainer}>
401
434
  {label && <label className={`${classes.prepend} ${disabled && classes.disabledPrepend}`}>{label}</label>}
402
- <div style={{ display: "flex" }}>
435
+ <div style={{ display: "flex" }} className="InputBase-input-wrapper">
403
436
  <InputBaseMUI
404
437
  classes={{
405
438
  input: classNames(classes.controlInput, inputBaseInputStyle),
@@ -414,7 +447,6 @@ const InputBase = ({ inputProps }) => {
414
447
  placeholder={placeholder}
415
448
  value={textToDisplay}
416
449
  fullWidth={true}
417
- onKeyDown={onKeyDown}
418
450
  onWheel={onWheel}
419
451
  onChange={event => onChangeHandler(event)}
420
452
  error={!!error}
@@ -982,6 +982,74 @@ describe("AdvancedNumericInput", () => {
982
982
  expect(btn.length, "to equal", 0);
983
983
  });
984
984
 
985
+ it("Advanced numeric input value without decimals, simulate onMouseDown to make code coverage happy", () => {
986
+ const inputProps = new InputBaseProps();
987
+ const aLabel = "aLabel";
988
+ const aValue = "";
989
+
990
+ inputProps.set(InputBaseProps.propNames.update, update);
991
+ inputProps.set(InputBaseProps.propNames.value, aValue);
992
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
993
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
994
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 0 });
995
+
996
+ const component = <InputBase inputProps={inputProps} />;
997
+ const mountedComponent = mount(component);
998
+ const btnIncrease = mountedComponent.find("[data-qa='increase']").hostNodes();
999
+ const btnDecrease = mountedComponent.find("[data-qa='decrease']").hostNodes();
1000
+
1001
+ btnIncrease.simulate("mouseDown");
1002
+ btnDecrease.simulate("mouseDown");
1003
+ });
1004
+
1005
+ it("Advanced numeric input value without decimals but with custom onKeyDown with prevent default", () => {
1006
+ const keydownSpy = sinon.stub().callsFake(e => {
1007
+ e.preventDefault();
1008
+ });
1009
+
1010
+ const inputProps = new InputBaseProps();
1011
+ const aLabel = "aLabel";
1012
+ const aValue = "";
1013
+
1014
+ inputProps.set(InputBaseProps.propNames.update, update);
1015
+ inputProps.set(InputBaseProps.propNames.value, aValue);
1016
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
1017
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
1018
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 0 });
1019
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { onKeyDown: keydownSpy });
1020
+
1021
+ const component = <InputBase inputProps={inputProps} />;
1022
+ const mountedComponent = mount(component);
1023
+ const input = mountedComponent.find("input");
1024
+ input.simulate("keydown", { key: "ArrowUp" });
1025
+
1026
+ expect(keydownSpy, "was called once");
1027
+ expect(update, "was not called");
1028
+ });
1029
+
1030
+ it("Advanced numeric input value without decimals but with custom onKeyDown without prevent default", () => {
1031
+ const keydownSpy = sinon.stub().callsFake(e => {});
1032
+
1033
+ const inputProps = new InputBaseProps();
1034
+ const aLabel = "aLabel";
1035
+ const aValue = "";
1036
+
1037
+ inputProps.set(InputBaseProps.propNames.update, update);
1038
+ inputProps.set(InputBaseProps.propNames.value, aValue);
1039
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
1040
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
1041
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 0 });
1042
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { onKeyDown: keydownSpy });
1043
+
1044
+ const component = <InputBase inputProps={inputProps} />;
1045
+ const mountedComponent = mount(component);
1046
+ const input = mountedComponent.find("input");
1047
+ input.simulate("keydown", { key: "ArrowUp" });
1048
+
1049
+ expect(keydownSpy, "was called once");
1050
+ expect(update, "to have calls satisfying", [{ args: ["1", null] }]);
1051
+ });
1052
+
985
1053
  it("Change advanced numeric input value, empty initial value with increase button", () => {
986
1054
  const inputProps = new InputBaseProps();
987
1055
  const aLabel = "aLabel";