Skip to content

Shift+Arrow steps by 1 instead of 10*step for string steps like "1.00" ("1e-7" becomes "1e-70") #761

Description

@trackoor

When step is a string whose fractional digits are all zeros (such as step="1.00" or step="1.0", used to preserve display precision) or scientific notation ("1e-7", 1e21), Shift + Arrow does not change the value by 10 * step: "1.00" steps by 1 ("1.000") instead of 10, and "1e-7" steps by 1e-70.

// npm i @rc-component/input-number@1.8.0 react@19.2.7 react-dom@19.2.7 @testing-library/react@16.3.2 jsdom@26
const React = require("react");
const { JSDOM } = require("jsdom");
const dom = new JSDOM("<!doctype html><html><body></body></html>");
Object.assign(global, {
  window: dom.window,
  document: dom.window.document,
  HTMLElement: dom.window.HTMLElement,
  Node: dom.window.Node,
});

const { render, fireEvent } = require("@testing-library/react");
const InputNumber = require("@rc-component/input-number").default;
const { getDecupleSteps } = require("@rc-component/input-number/lib/utils/numberUtil");

const { container } = render(
  React.createElement(InputNumber, {
    step: "1.00",
    defaultValue: 5,
    onStep: (value, info) => console.log("onStep:", value, info),
  })
);
const input = container.querySelector("input");
fireEvent.keyDown(input, { key: "ArrowUp", shiftKey: true });
console.log("input.value:", input.value);

for (const s of [1, 0.1, "1", "1.0", "1.00", "-1.0", "1e-7", 1e21]) {
  console.log(JSON.stringify(s), "->", JSON.stringify(getDecupleSteps(s)));
}

Command: node repro.cjs

Actual output:

onStep: 6 { offset: '1.000', type: 'up', emitter: 'keyboard' }
input.value: 6.00
1 -> "10"
0.1 -> "1"
"1" -> "10"
"1.0" -> "1.00"
"1.00" -> "1.000"
"-1.0" -> "-1.00"
"1e-7" -> "1e-70"
1e+21 -> "1e+210"

Expected output: onStep called with 15 and offset: '10', input.value: 15.00, and getDecupleSteps returning "10", "10", "-10", "0.000001", and "10000000000000000000000" for the last five inputs.

In src/utils/numberUtil.ts, getDecupleSteps normalizes the input into stepStr ("1.00" trims to "1" and 1e21 expands via num2str), but the !hasPoint branch returns step + '0' instead of using stepStr, and string scientific notation like "1e-7" is not expanded before shifting the decimal point.

Version: @rc-component/input-number@1.8.0 and master (868bd31), tested with react@19.2.7 on Node v26.13.0. (Feature added in #438.)

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions