Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentAuthCodeInput
Managercreate_auth_code_input_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { AuthCodeInput, create_auth_code_input_manager } from "sveltekit-ui"

  let completed_code = $state("")

  const manager = create_auth_code_input_manager({
    name: "verification_code",
    is_required: true,
    on_sixth: (code) => { completed_code = code },
  })
</script>

<label for={"auth_code_input_" + manager.id}>Six-digit verification code</label>
<AuthCodeInput {manager} />
{#if completed_code && manager.is_valid}<p role="status">Ready to verify {completed_code} with your server.</p>{/if}

API reference

Configure the manager, call its methods, and read its reactive state.

14 entries in configuration

PropertyTypeDefaultDescription
valstring nullcurrent 6-digit code value
namestring codename attribute for the input
is_requiredboolean falsemarks the input as required if true
is_read_onlyboolean falsemakes the input read-only if true
autocompletestring one-time-codedetermines the browser’s autocomplete type
is_validboolean nulloptionally control or reflect validation state
is_disabledboolean falsedisables the input if true
border_radiusnumber 1border radius for the input container in rem
mlnumber 0margin-left in rem
mrnumber 0margin-right in rem
mtnumber 0margin-top in rem
mbnumber 0margin-bottom in rem
on_changefunction nullcallback invoked when the input value changes, receives the cleaned value
on_sixthfunction nullcallback invoked when the input reaches 6 digits, receives the final code