@os-design/core 1.0.267 → 1.0.269
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/InputNumber/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAsB,EACpB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IACvD;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IAC7B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IAC5C;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3C;AAOD;;GAEG;AACH,QAAA,MAAM,WAAW,+
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/InputNumber/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAsB,EACpB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IACvD;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IAC7B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IAC5C;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3C;AAOD;;GAEG;AACH,QAAA,MAAM,WAAW,+GAqIhB,CAAC;AAIF,eAAe,WAAW,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getNextCaret, getNextState, numberToFormattedString, useGetCaretWithinValue, useValidate } from '@os-design/input-number-utils';
|
|
2
2
|
import { useForwardedRef } from '@os-design/utils';
|
|
3
|
-
import { forwardRef, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import Input from '../Input/index.js';
|
|
5
5
|
import defaultLocale from './utils/defaultLocale.js';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -20,6 +20,7 @@ const InputNumber = /*#__PURE__*/forwardRef(({
|
|
|
20
20
|
onChange = () => {},
|
|
21
21
|
onSelect = () => {},
|
|
22
22
|
onFocus = () => {},
|
|
23
|
+
onBlur = () => {},
|
|
23
24
|
...rest
|
|
24
25
|
}, ref) => {
|
|
25
26
|
useValidate({
|
|
@@ -47,6 +48,7 @@ const InputNumber = /*#__PURE__*/forwardRef(({
|
|
|
47
48
|
end: 0
|
|
48
49
|
});
|
|
49
50
|
const getCaretWithinValue = useGetCaretWithinValue(prefix, suffix);
|
|
51
|
+
const focusedRef = useRef(false);
|
|
50
52
|
|
|
51
53
|
// Update the value
|
|
52
54
|
useEffect(() => {
|
|
@@ -56,7 +58,9 @@ const InputNumber = /*#__PURE__*/forwardRef(({
|
|
|
56
58
|
// Update the selection
|
|
57
59
|
useEffect(() => {
|
|
58
60
|
if (!inputRef.current) return;
|
|
59
|
-
|
|
61
|
+
if (focusedRef.current) {
|
|
62
|
+
inputRef.current.setSelectionRange(selection.start, selection.end);
|
|
63
|
+
}
|
|
60
64
|
}, [inputRef, selection]);
|
|
61
65
|
return /*#__PURE__*/_jsx(Input, {
|
|
62
66
|
onSelect: e => {
|
|
@@ -74,13 +78,13 @@ const InputNumber = /*#__PURE__*/forwardRef(({
|
|
|
74
78
|
onSelect(e);
|
|
75
79
|
},
|
|
76
80
|
onFocus: e => {
|
|
77
|
-
|
|
78
|
-
setSelection({
|
|
79
|
-
start: getCaretWithinValue(valueString.length, valueString),
|
|
80
|
-
end: getCaretWithinValue(valueString.length, valueString)
|
|
81
|
-
});
|
|
81
|
+
focusedRef.current = true;
|
|
82
82
|
onFocus(e);
|
|
83
83
|
},
|
|
84
|
+
onBlur: e => {
|
|
85
|
+
focusedRef.current = false;
|
|
86
|
+
onBlur(e);
|
|
87
|
+
},
|
|
84
88
|
value: valueString,
|
|
85
89
|
onChange: (v, e) => {
|
|
86
90
|
// Get a new value as a string and number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.269",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"type": "module",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"react": "18",
|
|
59
59
|
"react-dom": "18"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "a2e831f273b33a71b957961fa0ab94ab8137861b"
|
|
62
62
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useValidate,
|
|
7
7
|
} from '@os-design/input-number-utils';
|
|
8
8
|
import { useForwardedRef } from '@os-design/utils';
|
|
9
|
-
import { forwardRef, useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import Input, { type InputProps } from '../Input/index.js';
|
|
11
11
|
import defaultLocale, {
|
|
12
12
|
type InputNumberLocale,
|
|
@@ -90,6 +90,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
90
90
|
onChange = () => {},
|
|
91
91
|
onSelect = () => {},
|
|
92
92
|
onFocus = () => {},
|
|
93
|
+
onBlur = () => {},
|
|
93
94
|
...rest
|
|
94
95
|
},
|
|
95
96
|
ref
|
|
@@ -132,6 +133,8 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
132
133
|
const [selection, setSelection] = useState<Selection>({ start: 0, end: 0 });
|
|
133
134
|
const getCaretWithinValue = useGetCaretWithinValue(prefix, suffix);
|
|
134
135
|
|
|
136
|
+
const focusedRef = useRef(false);
|
|
137
|
+
|
|
135
138
|
// Update the value
|
|
136
139
|
useEffect(() => {
|
|
137
140
|
setValueString(numberToFormattedString(value, options));
|
|
@@ -140,7 +143,9 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
140
143
|
// Update the selection
|
|
141
144
|
useEffect(() => {
|
|
142
145
|
if (!inputRef.current) return;
|
|
143
|
-
|
|
146
|
+
if (focusedRef.current) {
|
|
147
|
+
inputRef.current.setSelectionRange(selection.start, selection.end);
|
|
148
|
+
}
|
|
144
149
|
}, [inputRef, selection]);
|
|
145
150
|
|
|
146
151
|
return (
|
|
@@ -154,13 +159,13 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
154
159
|
onSelect(e);
|
|
155
160
|
}}
|
|
156
161
|
onFocus={(e) => {
|
|
157
|
-
|
|
158
|
-
setSelection({
|
|
159
|
-
start: getCaretWithinValue(valueString.length, valueString),
|
|
160
|
-
end: getCaretWithinValue(valueString.length, valueString),
|
|
161
|
-
});
|
|
162
|
+
focusedRef.current = true;
|
|
162
163
|
onFocus(e);
|
|
163
164
|
}}
|
|
165
|
+
onBlur={(e) => {
|
|
166
|
+
focusedRef.current = false;
|
|
167
|
+
onBlur(e);
|
|
168
|
+
}}
|
|
164
169
|
value={valueString}
|
|
165
170
|
onChange={(v, e) => {
|
|
166
171
|
// Get a new value as a string and number
|