GlassSecureField
Secure field with optional explicit reveal; its content is never logged.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-secure-field
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-secure-fieldCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| 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
@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
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.
Example
import SwiftUI
import SPGlassKit
public struct GlassSecureFieldExample: GlassExample {
public static let componentID = "glass-secure-field"
@State private var current = ""
@State private var new = ""
@State private var pin = ""
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
GlassSecureField("Current password", text: $current, validation: GlassFieldValidation(.required()))
GlassSecureField(
"New password",
text: $new,
prompt: "At least 12 characters",
helper: "Use a phrase you can remember.",
content: .newPassword,
allowsReveal: true,
validation: GlassFieldValidation(.required(), .minLength(12)),
validateOn: .always
)
GlassSecureField("Device PIN", text: $pin, allowsReveal: true, errorMessage: pin.isEmpty ? nil : "Demo: this PIN is always rejected.")
// Only the length is ever displayed: the example never prints the secret.
Text("New password length: \(new.count)")
.font(.callout)
.foregroundStyle(.secondary)
}
.padding()
}
}
}
#Preview("GlassSecureField") { GlassSecureFieldExample() }
Registry entry
| Identifier | glass-secure-field |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-forms-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassSecureContent, GlassSecureFieldReveal, GlassSecureField |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Forms/GlassSecureField.swift7889 bytes · sha256 ffe6641ac68a…