@laser-ui/components 2.6.0 → 2.6.1
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 +6 -0
- package/input/InputNumber.js +35 -25
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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.1](https://github.com/laser-ui/laser-ui/compare/v2.6.0...v2.6.1) (2026-04-09)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **components:** fix number input show ([d29f5eb](https://github.com/laser-ui/laser-ui/commit/d29f5eb7f89c55b0cc7da8a549731f55d05a7948))
|
|
10
|
+
|
|
5
11
|
# [2.6.0](https://github.com/laser-ui/laser-ui/compare/v2.5.0...v2.6.0) (2026-04-08)
|
|
6
12
|
|
|
7
13
|
### 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
|
}
|
|
@@ -113,28 +116,35 @@ export function InputNumber(props) {
|
|
|
113
116
|
_changeValue(num);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
}, onFocus: (e) => {
|
|
120
|
+
var _a;
|
|
121
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
122
|
+
setFocused(true);
|
|
116
123
|
}, onBlur: (e) => {
|
|
117
124
|
var _a;
|
|
118
125
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
119
|
-
|
|
126
|
+
setFocused(false);
|
|
127
|
+
let realValue = null;
|
|
120
128
|
if (placeholderValue.length === 0) {
|
|
121
|
-
|
|
129
|
+
realValue = null;
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
|
-
|
|
125
|
-
if (!isUndefined(max) &&
|
|
126
|
-
|
|
132
|
+
realValue = Number(placeholderValue);
|
|
133
|
+
if (!isUndefined(max) && realValue > max) {
|
|
134
|
+
realValue = max;
|
|
127
135
|
}
|
|
128
|
-
if (!isUndefined(min) &&
|
|
129
|
-
|
|
136
|
+
if (!isUndefined(min) && realValue < min) {
|
|
137
|
+
realValue = min;
|
|
130
138
|
}
|
|
131
|
-
if (integer && !Number.isInteger(
|
|
132
|
-
|
|
139
|
+
if (integer && !Number.isInteger(realValue)) {
|
|
140
|
+
realValue = Math.round(realValue);
|
|
133
141
|
}
|
|
134
|
-
val = num;
|
|
135
142
|
}
|
|
136
|
-
if (
|
|
137
|
-
changeValue(
|
|
143
|
+
if (realValue !== value) {
|
|
144
|
+
changeValue(realValue);
|
|
145
|
+
}
|
|
146
|
+
else if (realValue !== (placeholderValue.length === 0 ? null : Number(placeholderValue))) {
|
|
147
|
+
setPlaceholderValue(realValue === null ? '' : realValue.toString());
|
|
138
148
|
}
|
|
139
149
|
} })), 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
150
|
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.1",
|
|
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": "57a261d870b76433cf5365dde0fe7ffe9b486452"
|
|
41
41
|
}
|