@laser-ui/components 2.6.0 → 2.6.2
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.
- package/CHANGELOG.md +12 -0
- package/input/InputNumber.js +36 -34
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.6.2](https://github.com/laser-ui/laser-ui/compare/v2.6.1...v2.6.2) (2026-04-09)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **components:** always sync value and input ([7f09ac9](https://github.com/laser-ui/laser-ui/commit/7f09ac97eb6f4644cb5d31a2da842f6d5688ccc5))
|
|
10
|
+
|
|
11
|
+
## [2.6.1](https://github.com/laser-ui/laser-ui/compare/v2.6.0...v2.6.1) (2026-04-09)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- **components:** fix number input show ([d29f5eb](https://github.com/laser-ui/laser-ui/commit/d29f5eb7f89c55b0cc7da8a549731f55d05a7948))
|
|
16
|
+
|
|
5
17
|
# [2.6.0](https://github.com/laser-ui/laser-ui/compare/v2.5.0...v2.6.0) (2026-04-08)
|
|
6
18
|
|
|
7
19
|
### Bug Fixes
|
package/input/InputNumber.js
CHANGED
|
@@ -12,18 +12,6 @@ import { BaseInput } from '../base-input';
|
|
|
12
12
|
import { useComponentProps, useControlled, useDesign, useScopedProps, useStyled, useTranslation } from '../hooks';
|
|
13
13
|
import { Icon } from '../icon';
|
|
14
14
|
import { mergeCS } from '../utils';
|
|
15
|
-
function syncValueToPlaceholder(value, placeholder) {
|
|
16
|
-
if (isNull(value)) {
|
|
17
|
-
if (placeholder) {
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
if (value !== Number(placeholder)) {
|
|
23
|
-
return value.toString();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
15
|
export function InputNumber(props) {
|
|
28
16
|
const _a = useComponentProps('InputNumber', props), { styleOverrides, styleProvider, formControl, model, defaultModel, max, min, step = 1, integer = false, prefix, suffix, clearable, placeholder, size: sizeProp, numberButton = true, disabled: disabledProp = false, inputProps, onModelChange, onClear } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "formControl", "model", "defaultModel", "max", "min", "step", "integer", "prefix", "suffix", "clearable", "placeholder", "size", "numberButton", "disabled", "inputProps", "onModelChange", "onClear"]);
|
|
29
17
|
const styled = useStyled(CLASSES, { input: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.input }, styleOverrides);
|
|
@@ -32,9 +20,24 @@ export function InputNumber(props) {
|
|
|
32
20
|
const dataRef = useRef({});
|
|
33
21
|
const windowRef = useRefExtra(() => window);
|
|
34
22
|
const inputRef = useRef(null);
|
|
23
|
+
const [focused, setFocused] = useState(false);
|
|
35
24
|
const [value, _changeValue] = useControlled(defaultModel !== null && defaultModel !== void 0 ? defaultModel : null, model, onModelChange, undefined, formControl === null || formControl === void 0 ? void 0 : formControl.control);
|
|
36
25
|
const [placeholderValue, setPlaceholderValue] = useState(() => (isNull(value) ? '' : value.toString()));
|
|
37
|
-
const newPlaceholderValue =
|
|
26
|
+
const newPlaceholderValue = (() => {
|
|
27
|
+
if (focused) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (isNull(value)) {
|
|
31
|
+
if (placeholderValue) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (value !== Number(placeholderValue)) {
|
|
37
|
+
return value.toString();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
38
41
|
if (!isUndefined(newPlaceholderValue)) {
|
|
39
42
|
setPlaceholderValue(newPlaceholderValue);
|
|
40
43
|
}
|
|
@@ -104,37 +107,36 @@ export function InputNumber(props) {
|
|
|
104
107
|
};
|
|
105
108
|
}, value: placeholderValue, max: max, min: min, step: step, type: "number", placeholder: placeholder, disabled: disabled, onValueChange: (val) => {
|
|
106
109
|
setPlaceholderValue(val);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if ((isUndefined(max) || num <= max) && (isUndefined(min) || num >= min) && (!integer || Number.isInteger(num))) {
|
|
113
|
-
_changeValue(num);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
110
|
+
_changeValue(val.length === 0 ? null : Number(val));
|
|
111
|
+
}, onFocus: (e) => {
|
|
112
|
+
var _a;
|
|
113
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
114
|
+
setFocused(true);
|
|
116
115
|
}, onBlur: (e) => {
|
|
117
116
|
var _a;
|
|
118
117
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
119
|
-
|
|
118
|
+
setFocused(false);
|
|
119
|
+
let realValue = null;
|
|
120
120
|
if (placeholderValue.length === 0) {
|
|
121
|
-
|
|
121
|
+
realValue = null;
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
|
-
|
|
125
|
-
if (!isUndefined(max) &&
|
|
126
|
-
|
|
124
|
+
realValue = Number(placeholderValue);
|
|
125
|
+
if (!isUndefined(max) && realValue > max) {
|
|
126
|
+
realValue = max;
|
|
127
127
|
}
|
|
128
|
-
if (!isUndefined(min) &&
|
|
129
|
-
|
|
128
|
+
if (!isUndefined(min) && realValue < min) {
|
|
129
|
+
realValue = min;
|
|
130
130
|
}
|
|
131
|
-
if (integer && !Number.isInteger(
|
|
132
|
-
|
|
131
|
+
if (integer && !Number.isInteger(realValue)) {
|
|
132
|
+
realValue = Math.round(realValue);
|
|
133
133
|
}
|
|
134
|
-
val = num;
|
|
135
134
|
}
|
|
136
|
-
if (
|
|
137
|
-
changeValue(
|
|
135
|
+
if (realValue !== value) {
|
|
136
|
+
changeValue(realValue);
|
|
137
|
+
}
|
|
138
|
+
else if (realValue !== (placeholderValue.length === 0 ? null : Number(placeholderValue))) {
|
|
139
|
+
setPlaceholderValue(realValue === null ? '' : realValue.toString());
|
|
138
140
|
}
|
|
139
141
|
} })), clearable && !disabled && (_jsx("div", Object.assign({}, mergeCS(styled('input__clear'), { style: { opacity: placeholderValue.length > 0 ? 1 : 0 } }), { role: "button", "aria-label": t('Clear'), onClick: () => {
|
|
140
142
|
changeValue(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laser-ui/components",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"access": "public",
|
|
38
38
|
"directory": "../../dist/libs/components"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "44becbe9fcc81f5dab37ecf828d2fba9f25b1db6"
|
|
41
41
|
}
|