# AuthCodeInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/auth_code_input

Category: Input controls

renders a 6-digit numeric code input, typically used for one-time passcodes or verification codes

Public component import: `AuthCodeInput`

Public manager import: `create_auth_code_input_manager`

## Usage

```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}
```

## Configuration

### `val`

- type: string
- default: null
- description: current 6-digit code value

### `name`

- type: string
- default: code
- description: name attribute for the input

### `is_required`

- type: boolean
- default: false
- description: marks the input as required if true

### `is_read_only`

- type: boolean
- default: false
- description: makes the input read-only if true

### `autocomplete`

- type: string
- default: one-time-code
- description: determines the browser’s autocomplete type

### `is_valid`

- type: boolean
- default: null
- description: optionally control or reflect validation state

### `is_disabled`

- type: boolean
- default: false
- description: disables the input if true

### `border_radius`

- type: number
- default: 1
- description: border radius for the input container in rem

### `ml`

- type: number
- default: 0
- description: margin-left in rem

### `mr`

- type: number
- default: 0
- description: margin-right in rem

### `mt`

- type: number
- default: 0
- description: margin-top in rem

### `mb`

- type: number
- default: 0
- description: margin-bottom in rem

### `on_change`

- type: function
- default: null
- description: callback invoked when the input value changes, receives the cleaned value

### `on_sixth`

- type: function
- default: null
- description: callback invoked when the input reaches 6 digits, receives the final code

## Methods

### `set_val()`

- description: assigns a new code value to the input, strips non-numeric characters, calls on_change/on_sixth
- parameters:
  - input: string
- returns: void

### `focus()`

- description: programmatically focuses the input element
- parameters:
- returns: void

## Returned state

### `id`

- type: string
- description: unique identifier for the code input field

### `val`

- type: string
- description: current stored code value

### `name`

- type: string
- description: name attribute for the input field

### `is_required`

- type: boolean
- description: true if the input is required

### `is_read_only`

- type: boolean
- description: true if the code input is read-only

### `autocomplete`

- type: string
- description: the browser autocomplete type, often 'one-time-code'

### `is_valid`

- type: boolean
- description: reflects if the code is currently 6 digits

### `is_disabled`

- type: boolean
- description: disables input if true

### `border_radius`

- type: number
- description: border radius for the input container in rem

### `ml`

- type: number
- description: margin-left in rem

### `mr`

- type: number
- description: margin-right in rem

### `mt`

- type: number
- description: margin-top in rem

### `mb`

- type: number
- description: margin-bottom in rem
