From a301f8db11d738e15e60b7d43fdbfc76d65c3063 Mon Sep 17 00:00:00 2001 From: Jim <121858197+jneuendorf-i4h@users.noreply.github.com> Date: Thu, 13 Jun 2024 04:33:08 +0200 Subject: [PATCH] fix: do not dispatch "complete" event on mount (#26) Fixes #21 --- src/Pincode.svelte | 4 ++-- src/unstyled/Pincode.svelte | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pincode.svelte b/src/Pincode.svelte index fb3d80b..f8a952e 100644 --- a/src/Pincode.svelte +++ b/src/Pincode.svelte @@ -72,7 +72,7 @@ focusNextInput(idx); }, add: (id, value) => { - let _code = [...code]; + const _code = [...code]; _ids.update((_) => { if (code[_.length] === undefined) { @@ -157,7 +157,7 @@ $: _type.set(type); $: _selectTextOnFocus.set(selectTextOnFocus); $: value = code.join(""); - $: complete = code.filter(Boolean).length === $_ids.length; + $: complete = code.length > 0 && code.filter(Boolean).length === $_ids.length; $: if (code) { _ids.update((_) => { return _.map((_id, i) => ({ ..._id, value: code[i] })); diff --git a/src/unstyled/Pincode.svelte b/src/unstyled/Pincode.svelte index a00a213..f30e9dd 100644 --- a/src/unstyled/Pincode.svelte +++ b/src/unstyled/Pincode.svelte @@ -72,7 +72,7 @@ focusNextInput(idx); }, add: (id, value) => { - let _code = [...code]; + const _code = [...code]; _ids.update((_) => { if (code[_.length] === undefined) { @@ -157,7 +157,7 @@ $: _type.set(type); $: _selectTextOnFocus.set(selectTextOnFocus); $: value = code.join(""); - $: complete = code.filter(Boolean).length === $_ids.length; + $: complete = code.length > 0 && code.filter(Boolean).length === $_ids.length; $: if (code) { _ids.update((_) => { return _.map((_id, i) => ({ ..._id, value: code[i] }));