Skip to content

Commit df2506c

Browse files
committed
Fix bug InputNumberLocaled being invisible on Window blur
1 parent ae705fb commit df2506c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/components/parts/InputNumberLocaled.svelte

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ Two things are enhanced:
6262
if (actualInputUI) actualInputUI.focus();
6363
whenFocused = true;
6464
}
65+
66+
const onBlur = (e: Event) => {
67+
whenFocused = false;
68+
69+
// to ignore window itself get blurred - somehow not progressing to below prevents element's being invisible
70+
if (document.activeElement === e.target) {
71+
return;
72+
}
73+
74+
// tidy the input text to reflect the calculated value
75+
if (actualInputUI) {
76+
actualInputUI.value = integer.toString();
77+
}
78+
};
6579
</script>
6680

6781
<!-- inspired by https://github.com/yairEO/react-number-input but with a different approach of using two input tags instead of manipulating the text -->
@@ -92,14 +106,7 @@ Two things are enhanced:
92106
on:focus={() => {
93107
whenFocused = true;
94108
}}
95-
on:blur={() => {
96-
whenFocused = false;
97-
98-
// tidy the input text to reflect the calculated value
99-
if (actualInputUI) {
100-
actualInputUI.value = integer.toString();
101-
}
102-
}}
109+
on:blur={onBlur}
103110
on:change
104111
/>
105112
</div>

0 commit comments

Comments
 (0)