SPB Git

Repository Public MIT

glass-secure-field.md 3.0 KB

# GlassSecureField

Identifier glass-secure-field
Module SPGlassForms
Kind content-component — the system SecureField on an opaque themed surface
Platforms iOS 26, iPadOS 26, macOS 26
Example Examples/Gallery/Forms/GlassSecureFieldExample.swift

# Minimal usage

swift
@State private var password = ""

GlassSecureField("Password", text: $password)

# Variants

Variant Use
content: .password An existing password; password managers offer to fill it.
content: .newPassword A password being chosen; the system may suggest a strong one.
allowsReveal: true Adds a button that shows the content in clear. Off by default.
validation: / validateOn: / errorMessage: Same rules as GlassTextField.

# Parameters

Parameter Type Default Meaning
label LocalizedStringKey — Label above the field; also its accessibility label.
text Binding<String> — The secret.
prompt LocalizedStringKey? nil Placeholder.
helper LocalizedStringKey? nil Helper text.
systemImage String? nil Leading SF Symbol ("lock"), decorative (1.1).
content GlassSecureContent .password Content type for AutoFill.
allowsReveal Bool false Shows the reveal button.
validation GlassFieldValidation .none Rules of the field.
validateOn GlassValidationTrigger .afterEditing When the message starts to show.
errorMessage String? nil External error.

# States

Hidden (default, a SecureField), revealed (a TextField with autocorrection off and the password content type), focused, error, disabled. A disabled field is never shown in clear. The revealed state is local, starts hidden every time the field is created and is not stored anywhere.

# Advanced example

swift
GlassSecureField(
    "New password", text: $password,
    helper: "At least 12 characters.",
    content: .newPassword,
    allowsReveal: true,
    validation: GlassFieldValidation(.required(), .minLength(12)),
    errorMessage: model.passwordError
)
.onSubmit { model.changePassword(to: password) }

# Accessibility

  • The reveal button is labelled with the action it performs: "Show password", then "Hide password" (localised).
  • The button has the platform's minimum hit target and is reachable with the keyboard.
  • Errors are an icon and a sentence, not colour alone.
  • The field is marked privacySensitive(), so the system can redact it where it redacts private content.

# Limits

  • The component never logs, stores or copies the content; what the host does with the binding is its own responsibility.
  • Revealing swaps the secure field for a plain one; the focus is handed over in code, but the caret position is not kept.
  • GlassKit cannot prevent screen recording or screenshots.
  • AutoFill, strong password suggestions and the focus hand-over were not exercised on a running device here.
Files main
Menu

Theme