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

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
  }
@@ -411,7 +429,8 @@ var InputBase = function InputBase(_ref) {
411
429
  }, label), /*#__PURE__*/_react.default.createElement("div", {
412
430
  style: {
413
431
  display: "flex"
414
- }
432
+ },
433
+ className: "InputBase-input-wrapper"
415
434
  }, /*#__PURE__*/_react.default.createElement(_InputBase.default, {
416
435
  classes: {
417
436
  input: (0, _classnames.default)(classes.controlInput, inputBaseInputStyle),
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.3",
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
  }
@@ -399,7 +417,7 @@ const InputBase = ({ inputProps }) => {
399
417
  <div className={classes.container}>
400
418
  <div className={classes.inputContainer}>
401
419
  {label && <label className={`${classes.prepend} ${disabled && classes.disabledPrepend}`}>{label}</label>}
402
- <div style={{ display: "flex" }}>
420
+ <div style={{ display: "flex" }} className="InputBase-input-wrapper">
403
421
  <InputBaseMUI
404
422
  classes={{
405
423
  input: classNames(classes.controlInput, inputBaseInputStyle),
@@ -982,6 +982,26 @@ 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
+
985
1005
  it("Change advanced numeric input value, empty initial value with increase button", () => {
986
1006
  const inputProps = new InputBaseProps();
987
1007
  const aLabel = "aLabel";