SweetUI

Search items

Jump to an item

recipe

input-otp

One-time-code TextField, not a boxed control.

input-otpotpverification-codeone-time-codeguidance
input-otp, light

On iPad

The same installed source at a regular width. It adapts its layout without a separate design.

input-otp on iPad, light

Install

Usage

@State private var code = ""

TextField("One-time code", text: $code)
    .textContentType(.oneTimeCode)
    .keyboardType(.numberPad)
    .textFieldStyle(.registryInput)
    .font(.title2.monospacedDigit())
    .accessibilityLabel("Verification code")
    .onChange(of: code) { _, newValue in
        code = String(newValue.filter(\.isNumber).prefix(6))
    }
    .registryItem("input-otp")

Button("Verify") { }
    .buttonStyle(.registry)
    .disabled(code.count < 6)

Why native is enough

TextField + .textContentType(.oneTimeCode): offers Messages/Mail code above keyboard; .keyboardType(.numberPad): numeric. Six-box imitates, loses autofill. onChange caps 6 digits. No type: no offer.

Accessibility contract

  • Needs explicit label; title shows only as placeholder.
  • Monospaced-digit font: legible at large Dynamic Type.

Details

Kindrecipe
Version0.1.1
PlatformsiOS 26.0+
Dependenciesinput, button
Sourcenone (native guidance)