fix: input

This commit is contained in:
Torsten Dittmann committed 2024-02-27 20:17:50 +01:00
1 parent 43896ea044
commit e40452dd3f
3 files changed
+46 -24

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
diff --git a/src/lib/elements/forms/inputDigits.svelte b/src/lib/elements/forms/inputDigits.svelte
index dee662d63..7d54930f5 100644
--- a/src/lib/elements/forms/inputDigits.svelte
+++ b/src/lib/elements/forms/inputDigits.svelte
@@ -25,9 +25,15 @@
});
onMount(() => {
- if (element && autofocus) {
- element.querySelector('input')?.focus();
- }
+ const interval = setInterval(() => {
+ const input = element.querySelector('input');
+ if (element) {
+ if (input && autofocus) {
+ input.focus();
+ }
+ clearInterval(interval);
+ }
+ }, 10);
});
</script>
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 99cc475ff..c8c0239c7 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -54,6 +54,7 @@
'/recover',
'/invite',
'/card',
+ '/mfa',
'/hackathon'
];
if ($user) {
+9 -23
View File
@@ -33,30 +33,16 @@
}
});
/**
* TODO: Find proper solution.
* This spams focus for half a second.
* Autofocus works properly if +layout.ts is ssr = false. Seems like Svelte Kit bug.
* Using document.hasFocus doesnt help here
*/
async function focusInput(i = 0) {
if (i >= 10) {
return;
}
if (element && autofocus) {
element.querySelector('input')?.focus();
}
await tick();
setTimeout(() => {
focusInput(i + 1);
}, 50);
}
onMount(() => {
focusInput();
const interval = setInterval(() => {
const input = element.querySelector('input');
if (element) {
if (input && autofocus) {
input.focus();
}
clearInterval(interval);
}
}, 10);
});
</script>
+2 -1
View File
@@ -54,7 +54,8 @@
'/recover',
'/invite',
'/card',
'/hackathon'
'/hackathon',
'/mfa'
];
if ($user) {
if (