Note: This is heavily based on svelte-otp which is written in Svelte 4. This library adds some improvements.
one-time-code
auto fillnpm install svelte-input-otp
Getting started is as easy as importing the SvelteOtp
component and just using it.
<script>
import { OTPInput } from 'svelte-input-otp';
</script>
<OTPInput />
You can easily control the state of the value by binding it to the value
prop.
You can also change the number of inputs through the numOfInputs
prop.
<script>
import { OTPInput } from 'svelte-input-otp';
let value = $state('abc12');
</script>
<OTPInput numOfInputs={5} bind:value />