@ainias42/react-bootstrap-mobile 0.1.29 → 0.1.30

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * @ainias42/react-bootstrap-mobile v0.1.28
3
+ * @ainias42/react-bootstrap-mobile v0.1.29
4
4
  * git+https://github.com/Ainias/Bootstrap-React-Mobile.git
5
5
  * Copyright (c) Silas Günther and project contributors.
6
6
  * This source code is licensed under the MIT license found in the
@@ -23101,24 +23101,35 @@ const Input = withForwardRef(function Input(_a, ref) {
23101
23101
  className,
23102
23102
  style,
23103
23103
  onKeyDown,
23104
- inline = false
23104
+ inline = false,
23105
+ value
23105
23106
  } = _a,
23106
- otherProps = Input_rest(_a, ["label", "className", "style", "onKeyDown", "inline"]);
23107
+ otherProps = Input_rest(_a, ["label", "className", "style", "onKeyDown", "inline", "value"]);
23107
23108
  // States
23109
+ const usedValue = (0,external_react_.useMemo)(() => {
23110
+ if (otherProps.type !== "number" || typeof value === "number") {
23111
+ return value;
23112
+ }
23113
+ if (typeof value === "string") {
23114
+ if (!Number.isNaN(Number(value))) {
23115
+ // Do not parse to allow ., and so on
23116
+ return value;
23117
+ }
23118
+ if (!Number.isNaN(parseFloat(value))) {
23119
+ return parseFloat(value);
23120
+ }
23121
+ }
23122
+ return "";
23123
+ }, [value]);
23108
23124
  // Refs
23109
23125
  const innerRef = useComposedRef(ref);
23110
- const lastValueRef = (0,external_react_.useRef)(NaN);
23111
23126
  // Callbacks
23112
23127
  const [onChangeWithData, otherPropsWithoutOnchange] = useListenerWithExtractedProps('onChange', otherProps);
23113
23128
  const onChange = (0,external_react_.useCallback)(e => {
23114
23129
  if (otherProps.onChangeText) {
23115
23130
  if (otherProps.type === "number") {
23116
- if (Number.isNaN(e.target.valueAsNumber)) {
23117
- otherProps.onChangeText(lastValueRef.current);
23118
- } else {
23119
- otherProps.onChangeText(e.target.valueAsNumber);
23120
- lastValueRef.current = e.target.valueAsNumber;
23121
- }
23131
+ const val = !Number.isNaN(Number(e.target.value)) ? e.target.value : !Number.isNaN(parseFloat(e.target.value)) ? String(parseFloat(e.target.value)) : "";
23132
+ otherProps.onChangeText(val);
23122
23133
  } else {
23123
23134
  otherProps.onChangeText(e.target.value);
23124
23135
  }
@@ -23131,12 +23142,9 @@ const Input = withForwardRef(function Input(_a, ref) {
23131
23142
  onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
23132
23143
  if (otherProps.onEnter && e.key === 'Enter' && !e.defaultPrevented) {
23133
23144
  if (otherProps.type === "number") {
23134
- if (Number.isNaN(e.target.valueAsNumber)) {
23135
- otherProps.onEnter(lastValueRef.current);
23136
- } else {
23137
- otherProps.onEnter(e.target.valueAsNumber);
23138
- lastValueRef.current = e.target.valueAsNumber;
23139
- }
23145
+ const stringValue = e.target.value;
23146
+ const val = !Number.isNaN(Number(stringValue)) ? stringValue : !Number.isNaN(parseFloat(stringValue)) ? String(parseFloat(stringValue)) : "";
23147
+ otherProps.onEnter(val);
23140
23148
  } else {
23141
23149
  otherProps.onEnter(e.target.value);
23142
23150
  }
@@ -23156,7 +23164,11 @@ const Input = withForwardRef(function Input(_a, ref) {
23156
23164
  style: style
23157
23165
  }, label ? /*#__PURE__*/external_react_.createElement("span", {
23158
23166
  className: (input_default()).label
23159
- }, label) : null, /*#__PURE__*/external_react_.createElement("input", Input_extends({}, otherPropsWithoutData, {
23167
+ }, label) : null, /*#__PURE__*/external_react_.createElement("input", Input_extends({
23168
+ inputMode: otherProps.type === "number" ? "numeric" : undefined
23169
+ }, otherPropsWithoutData, {
23170
+ value: usedValue,
23171
+ type: otherProps.type === "number" ? "text" : otherProps.type,
23160
23172
  ref: innerRef,
23161
23173
  className: (input_default()).text,
23162
23174
  onBlur: onBlur,