Skip to content

Code Input

Last updated 27 Nov 2026

NbCodeInput takes a short code a person reads from somewhere else: a sign-in code from an email or an authenticator app, or a device code. It is one real text field drawn as a row of slots, so paste, autofill from a message and password managers all work as they do in any field.

Props ​

PropTypeDefaultDescription
modelValuestring''The code (v-model). Only the code's characters, never the separator
lengthnumber6How many characters. Ignored when groups is set
groupsnumber[]undefinedThe code split into groups, as [4, 4]. Overrides length
separatorstring'-'Drawn between groups, never part of the value
mode'numeric' | 'alphanumeric''numeric'What it takes. Also sets inputmode, so a phone opens the right keyboard
uppercasebooleanfalseTurns letters to capitals as they are typed or pasted
autocompletestring'one-time-code'The native autocomplete
state'idle' | 'verifying' | 'success' | 'error''idle'Where a check of the code stands
errorstring''The message under the slots, linked to the field
labelstringundefinedThe visible label. Without it the field is named "Verification code"
size'sm' | 'md' | 'lg''md'Slots 36, 44 or 52px wide. They shrink together in a narrower container
autofocusbooleanfalseTakes focus when mounted
disabledbooleanfalseTakes the field out of use, in place
idstringgeneratedThe input's id
namestringundefinedThe input's name, for a form submitted natively

Events ​

EventPayloadFired when
update:modelValuevalue: stringThe code changed, by typing, paste, autofill, clear() or an error
completevalue: stringThe code reached its full length. Once for each value that gets there

Methods ​

Through a template ref (ICodeInputExpose):

MethodDoes
focus()Puts focus in the field, with the caret after the code
clear()Empties the field and puts focus in it

States ​

stateWhat it draws
idleThe slots, the active one ringed
verifyingThe slots dimmed, NbInlineLoading running under them, and the field read only
successThe borders turn to the success colour left to right (--nb-motion-quick, 30ms apart), and a check
errorOne 6px shake (--nb-motion-long), danger borders, then the value clears and focus returns

Slots ​

None.

Strings ​

The names it speaks come from the string catalogue, so provideNbStrings() translates them: codeInputLabel, codeInputDigits(count), codeInputCharacters(count), codeInputVerifying and codeInputVerified.

Types ​

ts
import type {
  ICodeInputProps,
  ICodeInputExpose,
  TCodeInputMode,
  TCodeInputSize,
  TCodeInputState,
} from '@nubisco/ui'