InputNumber.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _typeof3 = require("@babel/runtime/helpers/typeof");
  4. Object.defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.default = void 0;
  8. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  9. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  10. var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
  11. var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
  12. var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
  13. var _miniDecimal = _interopRequireWildcard(require("@rc-component/mini-decimal"));
  14. var _classnames = _interopRequireDefault(require("classnames"));
  15. var _rcInput = require("rc-input");
  16. var _useLayoutEffect = require("rc-util/lib/hooks/useLayoutEffect");
  17. var _proxyObject = _interopRequireDefault(require("rc-util/lib/proxyObject"));
  18. var _ref = require("rc-util/lib/ref");
  19. var React = _interopRequireWildcard(require("react"));
  20. var _useCursor3 = _interopRequireDefault(require("./hooks/useCursor"));
  21. var _StepHandler = _interopRequireDefault(require("./StepHandler"));
  22. var _numberUtil = require("./utils/numberUtil");
  23. var _commonUtils = require("rc-input/lib/utils/commonUtils");
  24. var _useFrame = _interopRequireDefault(require("./hooks/useFrame"));
  25. var _excluded = ["prefixCls", "className", "style", "min", "max", "step", "defaultValue", "value", "disabled", "readOnly", "upHandler", "downHandler", "keyboard", "changeOnWheel", "controls", "classNames", "stringMode", "parser", "formatter", "precision", "decimalSeparator", "onChange", "onInput", "onPressEnter", "onStep", "changeOnBlur", "domRef"],
  26. _excluded2 = ["disabled", "style", "prefixCls", "value", "prefix", "suffix", "addonBefore", "addonAfter", "className", "classNames"];
  27. function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
  28. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
  29. /**
  30. * We support `stringMode` which need handle correct type when user call in onChange
  31. * format max or min value
  32. * 1. if isInvalid return null
  33. * 2. if precision is undefined, return decimal
  34. * 3. format with precision
  35. * I. if max > 0, round down with precision. Example: max= 3.5, precision=0 afterFormat: 3
  36. * II. if max < 0, round up with precision. Example: max= -3.5, precision=0 afterFormat: -4
  37. * III. if min > 0, round up with precision. Example: min= 3.5, precision=0 afterFormat: 4
  38. * IV. if min < 0, round down with precision. Example: max= -3.5, precision=0 afterFormat: -3
  39. */
  40. var getDecimalValue = function getDecimalValue(stringMode, decimalValue) {
  41. if (stringMode || decimalValue.isEmpty()) {
  42. return decimalValue.toString();
  43. }
  44. return decimalValue.toNumber();
  45. };
  46. var getDecimalIfValidate = function getDecimalIfValidate(value) {
  47. var decimal = (0, _miniDecimal.default)(value);
  48. return decimal.isInvalidate() ? null : decimal;
  49. };
  50. var InternalInputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
  51. var prefixCls = props.prefixCls,
  52. className = props.className,
  53. style = props.style,
  54. min = props.min,
  55. max = props.max,
  56. _props$step = props.step,
  57. step = _props$step === void 0 ? 1 : _props$step,
  58. defaultValue = props.defaultValue,
  59. value = props.value,
  60. disabled = props.disabled,
  61. readOnly = props.readOnly,
  62. upHandler = props.upHandler,
  63. downHandler = props.downHandler,
  64. keyboard = props.keyboard,
  65. _props$changeOnWheel = props.changeOnWheel,
  66. changeOnWheel = _props$changeOnWheel === void 0 ? false : _props$changeOnWheel,
  67. _props$controls = props.controls,
  68. controls = _props$controls === void 0 ? true : _props$controls,
  69. classNames = props.classNames,
  70. stringMode = props.stringMode,
  71. parser = props.parser,
  72. formatter = props.formatter,
  73. precision = props.precision,
  74. decimalSeparator = props.decimalSeparator,
  75. onChange = props.onChange,
  76. onInput = props.onInput,
  77. onPressEnter = props.onPressEnter,
  78. onStep = props.onStep,
  79. _props$changeOnBlur = props.changeOnBlur,
  80. changeOnBlur = _props$changeOnBlur === void 0 ? true : _props$changeOnBlur,
  81. domRef = props.domRef,
  82. inputProps = (0, _objectWithoutProperties2.default)(props, _excluded);
  83. var inputClassName = "".concat(prefixCls, "-input");
  84. var inputRef = React.useRef(null);
  85. var _React$useState = React.useState(false),
  86. _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
  87. focus = _React$useState2[0],
  88. setFocus = _React$useState2[1];
  89. var userTypingRef = React.useRef(false);
  90. var compositionRef = React.useRef(false);
  91. var shiftKeyRef = React.useRef(false);
  92. // ============================ Value =============================
  93. // Real value control
  94. var _React$useState3 = React.useState(function () {
  95. return (0, _miniDecimal.default)(value !== null && value !== void 0 ? value : defaultValue);
  96. }),
  97. _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
  98. decimalValue = _React$useState4[0],
  99. setDecimalValue = _React$useState4[1];
  100. function setUncontrolledDecimalValue(newDecimal) {
  101. if (value === undefined) {
  102. setDecimalValue(newDecimal);
  103. }
  104. }
  105. // ====================== Parser & Formatter ======================
  106. /**
  107. * `precision` is used for formatter & onChange.
  108. * It will auto generate by `value` & `step`.
  109. * But it will not block user typing.
  110. *
  111. * Note: Auto generate `precision` is used for legacy logic.
  112. * We should remove this since we already support high precision with BigInt.
  113. *
  114. * @param number Provide which number should calculate precision
  115. * @param userTyping Change by user typing
  116. */
  117. var getPrecision = React.useCallback(function (numStr, userTyping) {
  118. if (userTyping) {
  119. return undefined;
  120. }
  121. if (precision >= 0) {
  122. return precision;
  123. }
  124. return Math.max((0, _miniDecimal.getNumberPrecision)(numStr), (0, _miniDecimal.getNumberPrecision)(step));
  125. }, [precision, step]);
  126. // >>> Parser
  127. var mergedParser = React.useCallback(function (num) {
  128. var numStr = String(num);
  129. if (parser) {
  130. return parser(numStr);
  131. }
  132. var parsedStr = numStr;
  133. if (decimalSeparator) {
  134. parsedStr = parsedStr.replace(decimalSeparator, '.');
  135. }
  136. // [Legacy] We still support auto convert `$ 123,456` to `123456`
  137. return parsedStr.replace(/[^\w.-]+/g, '');
  138. }, [parser, decimalSeparator]);
  139. // >>> Formatter
  140. var inputValueRef = React.useRef('');
  141. var mergedFormatter = React.useCallback(function (number, userTyping) {
  142. if (formatter) {
  143. return formatter(number, {
  144. userTyping: userTyping,
  145. input: String(inputValueRef.current)
  146. });
  147. }
  148. var str = typeof number === 'number' ? (0, _miniDecimal.num2str)(number) : number;
  149. // User typing will not auto format with precision directly
  150. if (!userTyping) {
  151. var mergedPrecision = getPrecision(str, userTyping);
  152. if ((0, _miniDecimal.validateNumber)(str) && (decimalSeparator || mergedPrecision >= 0)) {
  153. // Separator
  154. var separatorStr = decimalSeparator || '.';
  155. str = (0, _miniDecimal.toFixed)(str, separatorStr, mergedPrecision);
  156. }
  157. }
  158. return str;
  159. }, [formatter, getPrecision, decimalSeparator]);
  160. // ========================== InputValue ==========================
  161. /**
  162. * Input text value control
  163. *
  164. * User can not update input content directly. It updates with follow rules by priority:
  165. * 1. controlled `value` changed
  166. * * [SPECIAL] Typing like `1.` should not immediately convert to `1`
  167. * 2. User typing with format (not precision)
  168. * 3. Blur or Enter trigger revalidate
  169. */
  170. var _React$useState5 = React.useState(function () {
  171. var initValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value;
  172. if (decimalValue.isInvalidate() && ['string', 'number'].includes((0, _typeof2.default)(initValue))) {
  173. return Number.isNaN(initValue) ? '' : initValue;
  174. }
  175. return mergedFormatter(decimalValue.toString(), false);
  176. }),
  177. _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
  178. inputValue = _React$useState6[0],
  179. setInternalInputValue = _React$useState6[1];
  180. inputValueRef.current = inputValue;
  181. // Should always be string
  182. function setInputValue(newValue, userTyping) {
  183. setInternalInputValue(mergedFormatter(
  184. // Invalidate number is sometime passed by external control, we should let it go
  185. // Otherwise is controlled by internal interactive logic which check by userTyping
  186. // You can ref 'show limited value when input is not focused' test for more info.
  187. newValue.isInvalidate() ? newValue.toString(false) : newValue.toString(!userTyping), userTyping));
  188. }
  189. // >>> Max & Min limit
  190. var maxDecimal = React.useMemo(function () {
  191. return getDecimalIfValidate(max);
  192. }, [max, precision]);
  193. var minDecimal = React.useMemo(function () {
  194. return getDecimalIfValidate(min);
  195. }, [min, precision]);
  196. var upDisabled = React.useMemo(function () {
  197. if (!maxDecimal || !decimalValue || decimalValue.isInvalidate()) {
  198. return false;
  199. }
  200. return maxDecimal.lessEquals(decimalValue);
  201. }, [maxDecimal, decimalValue]);
  202. var downDisabled = React.useMemo(function () {
  203. if (!minDecimal || !decimalValue || decimalValue.isInvalidate()) {
  204. return false;
  205. }
  206. return decimalValue.lessEquals(minDecimal);
  207. }, [minDecimal, decimalValue]);
  208. // Cursor controller
  209. var _useCursor = (0, _useCursor3.default)(inputRef.current, focus),
  210. _useCursor2 = (0, _slicedToArray2.default)(_useCursor, 2),
  211. recordCursor = _useCursor2[0],
  212. restoreCursor = _useCursor2[1];
  213. // ============================= Data =============================
  214. /**
  215. * Find target value closet within range.
  216. * e.g. [11, 28]:
  217. * 3 => 11
  218. * 23 => 23
  219. * 99 => 28
  220. */
  221. var getRangeValue = function getRangeValue(target) {
  222. // target > max
  223. if (maxDecimal && !target.lessEquals(maxDecimal)) {
  224. return maxDecimal;
  225. }
  226. // target < min
  227. if (minDecimal && !minDecimal.lessEquals(target)) {
  228. return minDecimal;
  229. }
  230. return null;
  231. };
  232. /**
  233. * Check value is in [min, max] range
  234. */
  235. var isInRange = function isInRange(target) {
  236. return !getRangeValue(target);
  237. };
  238. /**
  239. * Trigger `onChange` if value validated and not equals of origin.
  240. * Return the value that re-align in range.
  241. */
  242. var triggerValueUpdate = function triggerValueUpdate(newValue, userTyping) {
  243. var updateValue = newValue;
  244. var isRangeValidate = isInRange(updateValue) || updateValue.isEmpty();
  245. // Skip align value when trigger value is empty.
  246. // We just trigger onChange(null)
  247. // This should not block user typing
  248. if (!updateValue.isEmpty() && !userTyping) {
  249. // Revert value in range if needed
  250. updateValue = getRangeValue(updateValue) || updateValue;
  251. isRangeValidate = true;
  252. }
  253. if (!readOnly && !disabled && isRangeValidate) {
  254. var numStr = updateValue.toString();
  255. var mergedPrecision = getPrecision(numStr, userTyping);
  256. if (mergedPrecision >= 0) {
  257. updateValue = (0, _miniDecimal.default)((0, _miniDecimal.toFixed)(numStr, '.', mergedPrecision));
  258. // When to fixed. The value may out of min & max range.
  259. // 4 in [0, 3.8] => 3.8 => 4 (toFixed)
  260. if (!isInRange(updateValue)) {
  261. updateValue = (0, _miniDecimal.default)((0, _miniDecimal.toFixed)(numStr, '.', mergedPrecision, true));
  262. }
  263. }
  264. // Trigger event
  265. if (!updateValue.equals(decimalValue)) {
  266. setUncontrolledDecimalValue(updateValue);
  267. onChange === null || onChange === void 0 || onChange(updateValue.isEmpty() ? null : getDecimalValue(stringMode, updateValue));
  268. // Reformat input if value is not controlled
  269. if (value === undefined) {
  270. setInputValue(updateValue, userTyping);
  271. }
  272. }
  273. return updateValue;
  274. }
  275. return decimalValue;
  276. };
  277. // ========================== User Input ==========================
  278. var onNextPromise = (0, _useFrame.default)();
  279. // >>> Collect input value
  280. var collectInputValue = function collectInputValue(inputStr) {
  281. recordCursor();
  282. // Update inputValue in case input can not parse as number
  283. // Refresh ref value immediately since it may used by formatter
  284. inputValueRef.current = inputStr;
  285. setInternalInputValue(inputStr);
  286. // Parse number
  287. if (!compositionRef.current) {
  288. var finalValue = mergedParser(inputStr);
  289. var finalDecimal = (0, _miniDecimal.default)(finalValue);
  290. if (!finalDecimal.isNaN()) {
  291. triggerValueUpdate(finalDecimal, true);
  292. }
  293. }
  294. // Trigger onInput later to let user customize value if they want to handle something after onChange
  295. onInput === null || onInput === void 0 || onInput(inputStr);
  296. // optimize for chinese input experience
  297. // https://github.com/ant-design/ant-design/issues/8196
  298. onNextPromise(function () {
  299. var nextInputStr = inputStr;
  300. if (!parser) {
  301. nextInputStr = inputStr.replace(/。/g, '.');
  302. }
  303. if (nextInputStr !== inputStr) {
  304. collectInputValue(nextInputStr);
  305. }
  306. });
  307. };
  308. // >>> Composition
  309. var onCompositionStart = function onCompositionStart() {
  310. compositionRef.current = true;
  311. };
  312. var onCompositionEnd = function onCompositionEnd() {
  313. compositionRef.current = false;
  314. collectInputValue(inputRef.current.value);
  315. };
  316. // >>> Input
  317. var onInternalInput = function onInternalInput(e) {
  318. collectInputValue(e.target.value);
  319. };
  320. // ============================= Step =============================
  321. var onInternalStep = function onInternalStep(up) {
  322. var _inputRef$current;
  323. // Ignore step since out of range
  324. if (up && upDisabled || !up && downDisabled) {
  325. return;
  326. }
  327. // Clear typing status since it may be caused by up & down key.
  328. // We should sync with input value.
  329. userTypingRef.current = false;
  330. var stepDecimal = (0, _miniDecimal.default)(shiftKeyRef.current ? (0, _numberUtil.getDecupleSteps)(step) : step);
  331. if (!up) {
  332. stepDecimal = stepDecimal.negate();
  333. }
  334. var target = (decimalValue || (0, _miniDecimal.default)(0)).add(stepDecimal.toString());
  335. var updatedValue = triggerValueUpdate(target, false);
  336. onStep === null || onStep === void 0 || onStep(getDecimalValue(stringMode, updatedValue), {
  337. offset: shiftKeyRef.current ? (0, _numberUtil.getDecupleSteps)(step) : step,
  338. type: up ? 'up' : 'down'
  339. });
  340. (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
  341. };
  342. // ============================ Flush =============================
  343. /**
  344. * Flush current input content to trigger value change & re-formatter input if needed.
  345. * This will always flush input value for update.
  346. * If it's invalidate, will fallback to last validate value.
  347. */
  348. var flushInputValue = function flushInputValue(userTyping) {
  349. var parsedValue = (0, _miniDecimal.default)(mergedParser(inputValue));
  350. var formatValue;
  351. if (!parsedValue.isNaN()) {
  352. // Only validate value or empty value can be re-fill to inputValue
  353. // Reassign the formatValue within ranged of trigger control
  354. formatValue = triggerValueUpdate(parsedValue, userTyping);
  355. } else {
  356. formatValue = triggerValueUpdate(decimalValue, userTyping);
  357. }
  358. if (value !== undefined) {
  359. // Reset back with controlled value first
  360. setInputValue(decimalValue, false);
  361. } else if (!formatValue.isNaN()) {
  362. // Reset input back since no validate value
  363. setInputValue(formatValue, false);
  364. }
  365. };
  366. // Solve the issue of the event triggering sequence when entering numbers in chinese input (Safari)
  367. var onBeforeInput = function onBeforeInput() {
  368. userTypingRef.current = true;
  369. };
  370. var onKeyDown = function onKeyDown(event) {
  371. var key = event.key,
  372. shiftKey = event.shiftKey;
  373. userTypingRef.current = true;
  374. shiftKeyRef.current = shiftKey;
  375. if (key === 'Enter') {
  376. if (!compositionRef.current) {
  377. userTypingRef.current = false;
  378. }
  379. flushInputValue(false);
  380. onPressEnter === null || onPressEnter === void 0 || onPressEnter(event);
  381. }
  382. if (keyboard === false) {
  383. return;
  384. }
  385. // Do step
  386. if (!compositionRef.current && ['Up', 'ArrowUp', 'Down', 'ArrowDown'].includes(key)) {
  387. onInternalStep(key === 'Up' || key === 'ArrowUp');
  388. event.preventDefault();
  389. }
  390. };
  391. var onKeyUp = function onKeyUp() {
  392. userTypingRef.current = false;
  393. shiftKeyRef.current = false;
  394. };
  395. React.useEffect(function () {
  396. if (changeOnWheel && focus) {
  397. var onWheel = function onWheel(event) {
  398. // moving mouse wheel rises wheel event with deltaY < 0
  399. // scroll value grows from top to bottom, as screen Y coordinate
  400. onInternalStep(event.deltaY < 0);
  401. event.preventDefault();
  402. };
  403. var input = inputRef.current;
  404. if (input) {
  405. // React onWheel is passive and we can't preventDefault() in it.
  406. // That's why we should subscribe with DOM listener
  407. // https://stackoverflow.com/questions/63663025/react-onwheel-handler-cant-preventdefault-because-its-a-passive-event-listenev
  408. input.addEventListener('wheel', onWheel, {
  409. passive: false
  410. });
  411. return function () {
  412. return input.removeEventListener('wheel', onWheel);
  413. };
  414. }
  415. }
  416. });
  417. // >>> Focus & Blur
  418. var onBlur = function onBlur() {
  419. if (changeOnBlur) {
  420. flushInputValue(false);
  421. }
  422. setFocus(false);
  423. userTypingRef.current = false;
  424. };
  425. // ========================== Controlled ==========================
  426. // Input by precision & formatter
  427. (0, _useLayoutEffect.useLayoutUpdateEffect)(function () {
  428. if (!decimalValue.isInvalidate()) {
  429. setInputValue(decimalValue, false);
  430. }
  431. }, [precision, formatter]);
  432. // Input by value
  433. (0, _useLayoutEffect.useLayoutUpdateEffect)(function () {
  434. var newValue = (0, _miniDecimal.default)(value);
  435. setDecimalValue(newValue);
  436. var currentParsedValue = (0, _miniDecimal.default)(mergedParser(inputValue));
  437. // When user typing from `1.2` to `1.`, we should not convert to `1` immediately.
  438. // But let it go if user set `formatter`
  439. if (!newValue.equals(currentParsedValue) || !userTypingRef.current || formatter) {
  440. // Update value as effect
  441. setInputValue(newValue, userTypingRef.current);
  442. }
  443. }, [value]);
  444. // ============================ Cursor ============================
  445. (0, _useLayoutEffect.useLayoutUpdateEffect)(function () {
  446. if (formatter) {
  447. restoreCursor();
  448. }
  449. }, [inputValue]);
  450. // ============================ Render ============================
  451. return /*#__PURE__*/React.createElement("div", {
  452. ref: domRef,
  453. className: (0, _classnames.default)(prefixCls, className, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, "".concat(prefixCls, "-focused"), focus), "".concat(prefixCls, "-disabled"), disabled), "".concat(prefixCls, "-readonly"), readOnly), "".concat(prefixCls, "-not-a-number"), decimalValue.isNaN()), "".concat(prefixCls, "-out-of-range"), !decimalValue.isInvalidate() && !isInRange(decimalValue))),
  454. style: style,
  455. onFocus: function onFocus() {
  456. setFocus(true);
  457. },
  458. onBlur: onBlur,
  459. onKeyDown: onKeyDown,
  460. onKeyUp: onKeyUp,
  461. onCompositionStart: onCompositionStart,
  462. onCompositionEnd: onCompositionEnd,
  463. onBeforeInput: onBeforeInput
  464. }, controls && /*#__PURE__*/React.createElement(_StepHandler.default, {
  465. prefixCls: prefixCls,
  466. upNode: upHandler,
  467. downNode: downHandler,
  468. upDisabled: upDisabled,
  469. downDisabled: downDisabled,
  470. onStep: onInternalStep
  471. }), /*#__PURE__*/React.createElement("div", {
  472. className: "".concat(inputClassName, "-wrap")
  473. }, /*#__PURE__*/React.createElement("input", (0, _extends2.default)({
  474. autoComplete: "off",
  475. role: "spinbutton",
  476. "aria-valuemin": min,
  477. "aria-valuemax": max,
  478. "aria-valuenow": decimalValue.isInvalidate() ? null : decimalValue.toString(),
  479. step: step
  480. }, inputProps, {
  481. ref: (0, _ref.composeRef)(inputRef, ref),
  482. className: inputClassName,
  483. value: inputValue,
  484. onChange: onInternalInput,
  485. disabled: disabled,
  486. readOnly: readOnly
  487. }))));
  488. });
  489. var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
  490. var disabled = props.disabled,
  491. style = props.style,
  492. _props$prefixCls = props.prefixCls,
  493. prefixCls = _props$prefixCls === void 0 ? 'rc-input-number' : _props$prefixCls,
  494. value = props.value,
  495. prefix = props.prefix,
  496. suffix = props.suffix,
  497. addonBefore = props.addonBefore,
  498. addonAfter = props.addonAfter,
  499. className = props.className,
  500. classNames = props.classNames,
  501. rest = (0, _objectWithoutProperties2.default)(props, _excluded2);
  502. var holderRef = React.useRef(null);
  503. var inputNumberDomRef = React.useRef(null);
  504. var inputFocusRef = React.useRef(null);
  505. var focus = function focus(option) {
  506. if (inputFocusRef.current) {
  507. (0, _commonUtils.triggerFocus)(inputFocusRef.current, option);
  508. }
  509. };
  510. React.useImperativeHandle(ref, function () {
  511. return (0, _proxyObject.default)(inputFocusRef.current, {
  512. focus: focus,
  513. nativeElement: holderRef.current.nativeElement || inputNumberDomRef.current
  514. });
  515. });
  516. return /*#__PURE__*/React.createElement(_rcInput.BaseInput, {
  517. className: className,
  518. triggerFocus: focus,
  519. prefixCls: prefixCls,
  520. value: value,
  521. disabled: disabled,
  522. style: style,
  523. prefix: prefix,
  524. suffix: suffix,
  525. addonAfter: addonAfter,
  526. addonBefore: addonBefore,
  527. classNames: classNames,
  528. components: {
  529. affixWrapper: 'div',
  530. groupWrapper: 'div',
  531. wrapper: 'div',
  532. groupAddon: 'div'
  533. },
  534. ref: holderRef
  535. }, /*#__PURE__*/React.createElement(InternalInputNumber, (0, _extends2.default)({
  536. prefixCls: prefixCls,
  537. disabled: disabled,
  538. ref: inputFocusRef,
  539. domRef: inputNumberDomRef,
  540. className: classNames === null || classNames === void 0 ? void 0 : classNames.input
  541. }, rest)));
  542. });
  543. if (process.env.NODE_ENV !== 'production') {
  544. InputNumber.displayName = 'InputNumber';
  545. }
  546. var _default = exports.default = InputNumber;