orc-shared 5.10.2-dev.3 → 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.
@@ -420,6 +420,19 @@ var InputBase = function InputBase(_ref) {
420
420
 
421
421
  // eslint-disable-next-line react-hooks/exhaustive-deps
422
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
+ }
423
436
  return /*#__PURE__*/_react.default.createElement("div", {
424
437
  className: classes.container
425
438
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -445,7 +458,6 @@ var InputBase = function InputBase(_ref) {
445
458
  placeholder: placeholder,
446
459
  value: textToDisplay,
447
460
  fullWidth: true,
448
- onKeyDown: onKeyDown,
449
461
  onWheel: onWheel,
450
462
  onChange: function onChange(event) {
451
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.3",
3
+ "version": "5.10.2-dev.4",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -413,6 +413,21 @@ const InputBase = ({ inputProps }) => {
413
413
  // eslint-disable-next-line react-hooks/exhaustive-deps
414
414
  }, [inputText, metadata, timeoutDelay, update, value]);
415
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
+
416
431
  return (
417
432
  <div className={classes.container}>
418
433
  <div className={classes.inputContainer}>
@@ -432,7 +447,6 @@ const InputBase = ({ inputProps }) => {
432
447
  placeholder={placeholder}
433
448
  value={textToDisplay}
434
449
  fullWidth={true}
435
- onKeyDown={onKeyDown}
436
450
  onWheel={onWheel}
437
451
  onChange={event => onChangeHandler(event)}
438
452
  error={!!error}
@@ -1002,6 +1002,54 @@ describe("AdvancedNumericInput", () => {
1002
1002
  btnDecrease.simulate("mouseDown");
1003
1003
  });
1004
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
+
1005
1053
  it("Change advanced numeric input value, empty initial value with increase button", () => {
1006
1054
  const inputProps = new InputBaseProps();
1007
1055
  const aLabel = "aLabel";