@team-monolith/cds 1.13.2 → 1.14.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.
|
@@ -19,6 +19,18 @@ export default function SegmentedInput(props) {
|
|
|
19
19
|
const splitedValues = value.split("").filter((v) => v !== " ");
|
|
20
20
|
const [focusedIndex, setFocusedIndex] = useState(null);
|
|
21
21
|
const hiddenRef = useRef(null);
|
|
22
|
+
// value의 공백을 제거하고, format에 맞춰 공백을 추가한 값을 리턴합니다.
|
|
23
|
+
const getFormattedValue = (value) => {
|
|
24
|
+
const despacedValue = value.replace(/ /g, "");
|
|
25
|
+
return despacedValue.split("").reduce((prev, curr, i) => {
|
|
26
|
+
if (leftSpacedIndexs.includes(i)) {
|
|
27
|
+
return prev + " " + curr;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return prev + curr;
|
|
31
|
+
}
|
|
32
|
+
}, "");
|
|
33
|
+
};
|
|
22
34
|
return (_jsxs(Container, { children: [_jsx("input", { type: "input", ref: hiddenRef, value: splitedValues.join(""), readOnly: readOnly, onKeyDown: (e) => {
|
|
23
35
|
if (e.key === "ArrowLeft") {
|
|
24
36
|
if (focusedIndex !== null && focusedIndex > 0) {
|
|
@@ -33,15 +45,12 @@ export default function SegmentedInput(props) {
|
|
|
33
45
|
}
|
|
34
46
|
}, onChange: (event) => {
|
|
35
47
|
var _a;
|
|
36
|
-
onChange(event.target.value);
|
|
48
|
+
onChange(getFormattedValue(event.target.value));
|
|
37
49
|
const selectionStart = (_a = hiddenRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart;
|
|
38
50
|
setFocusedIndex(selectionStart ? selectionStart - 1 : null);
|
|
39
51
|
}, onBlur: (e) => {
|
|
52
|
+
onChange(getFormattedValue(e.target.value).slice(0, answerFormat.length));
|
|
40
53
|
setFocusedIndex(null);
|
|
41
|
-
const eventValue = e.target.value;
|
|
42
|
-
if (eventValue.length > despacedFormat.length) {
|
|
43
|
-
onChange(eventValue.slice(0, despacedFormat.length));
|
|
44
|
-
}
|
|
45
54
|
}, css: css `
|
|
46
55
|
opacity: 0;
|
|
47
56
|
height: 0;
|