@os-design/core 1.0.268 → 1.0.270

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,+GAuHhB,CAAC;AAIF,eAAe,WAAW,CAAC"}
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";
@@ -19,6 +19,8 @@ const InputNumber = /*#__PURE__*/forwardRef(({
19
19
  value = null,
20
20
  onChange = () => {},
21
21
  onSelect = () => {},
22
+ onFocus = () => {},
23
+ onBlur = () => {},
22
24
  ...rest
23
25
  }, ref) => {
24
26
  useValidate({
@@ -46,6 +48,7 @@ const InputNumber = /*#__PURE__*/forwardRef(({
46
48
  end: 0
47
49
  });
48
50
  const getCaretWithinValue = useGetCaretWithinValue(prefix, suffix);
51
+ const focusedRef = useRef(false);
49
52
 
50
53
  // Update the value
51
54
  useEffect(() => {
@@ -55,7 +58,9 @@ const InputNumber = /*#__PURE__*/forwardRef(({
55
58
  // Update the selection
56
59
  useEffect(() => {
57
60
  if (!inputRef.current) return;
58
- inputRef.current.setSelectionRange(selection.start, selection.end);
61
+ if (focusedRef.current) {
62
+ inputRef.current.setSelectionRange(selection.start, selection.end);
63
+ }
59
64
  }, [inputRef, selection]);
60
65
  return /*#__PURE__*/_jsx(Input, {
61
66
  onSelect: e => {
@@ -72,6 +77,14 @@ const InputNumber = /*#__PURE__*/forwardRef(({
72
77
  });
73
78
  onSelect(e);
74
79
  },
80
+ onFocus: e => {
81
+ focusedRef.current = true;
82
+ onFocus(e);
83
+ },
84
+ onBlur: e => {
85
+ focusedRef.current = false;
86
+ onBlur(e);
87
+ },
75
88
  value: valueString,
76
89
  onChange: (v, e) => {
77
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.268",
3
+ "version": "1.0.270",
4
4
  "license": "UNLICENSED",
5
5
  "repository": "git@gitlab.com:os-team/libs/os-design.git",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "@os-design/styles": "^1.0.65",
40
40
  "@os-design/theming": "^1.0.61",
41
41
  "@os-design/time-picker-utils": "^1.0.23",
42
- "@os-design/utils": "^1.0.85",
42
+ "@os-design/utils": "^1.0.86",
43
43
  "facepaint": "^1.2.1",
44
44
  "react-focus-lock": "^2.13.2",
45
45
  "react-window": "^1.8.10"
@@ -58,5 +58,5 @@
58
58
  "react": "18",
59
59
  "react-dom": "18"
60
60
  },
61
- "gitHead": "f0fa83bbb9597b879a8e1b421cc3d776dc370cc2"
61
+ "gitHead": "32672b12ae0a6483602c25f5bde36fac4a8fa64d"
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,
@@ -89,6 +89,8 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
89
89
  value = null,
90
90
  onChange = () => {},
91
91
  onSelect = () => {},
92
+ onFocus = () => {},
93
+ onBlur = () => {},
92
94
  ...rest
93
95
  },
94
96
  ref
@@ -131,6 +133,8 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
131
133
  const [selection, setSelection] = useState<Selection>({ start: 0, end: 0 });
132
134
  const getCaretWithinValue = useGetCaretWithinValue(prefix, suffix);
133
135
 
136
+ const focusedRef = useRef(false);
137
+
134
138
  // Update the value
135
139
  useEffect(() => {
136
140
  setValueString(numberToFormattedString(value, options));
@@ -139,7 +143,9 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
139
143
  // Update the selection
140
144
  useEffect(() => {
141
145
  if (!inputRef.current) return;
142
- inputRef.current.setSelectionRange(selection.start, selection.end);
146
+ if (focusedRef.current) {
147
+ inputRef.current.setSelectionRange(selection.start, selection.end);
148
+ }
143
149
  }, [inputRef, selection]);
144
150
 
145
151
  return (
@@ -152,6 +158,14 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(
152
158
  setSelection({ start: selectionStart || 0, end: selectionEnd || 0 });
153
159
  onSelect(e);
154
160
  }}
161
+ onFocus={(e) => {
162
+ focusedRef.current = true;
163
+ onFocus(e);
164
+ }}
165
+ onBlur={(e) => {
166
+ focusedRef.current = false;
167
+ onBlur(e);
168
+ }}
155
169
  value={valueString}
156
170
  onChange={(v, e) => {
157
171
  // Get a new value as a string and number