SPB Git

Repository Public MIT

doc-glass-secure-field.md 3.0 KB 74 lines markdown

1# GlassSecureField23| | |4|---|---|5| Identifier | `glass-secure-field` |6| Module | `SPGlassForms` |7| Kind | `content-component` — the system `SecureField` on an opaque themed surface |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Forms/GlassSecureFieldExample.swift` |1011## Minimal usage1213```swift14@State private var password = ""1516GlassSecureField("Password", text: $password)17```1819## Variants2021| Variant | Use |22|---|---|23| `content: .password` | An existing password; password managers offer to fill it. |24| `content: .newPassword` | A password being chosen; the system may suggest a strong one. |25| `allowsReveal: true` | Adds a button that shows the content in clear. Off by default. |26| `validation:` / `validateOn:` / `errorMessage:` | Same rules as `GlassTextField`. |2728## Parameters2930| Parameter | Type | Default | Meaning |31|---|---|---|---|32| `label` | `LocalizedStringKey` | — | Label above the field; also its accessibility label. |33| `text` | `Binding<String>` | — | The secret. |34| `prompt` | `LocalizedStringKey?` | `nil` | Placeholder. |35| `helper` | `LocalizedStringKey?` | `nil` | Helper text. |36| `systemImage` | `String?` | `nil` | Leading SF Symbol (`"lock"`), decorative (1.1). |37| `content` | `GlassSecureContent` | `.password` | Content type for AutoFill. |38| `allowsReveal` | `Bool` | `false` | Shows the reveal button. |39| `validation` | `GlassFieldValidation` | `.none` | Rules of the field. |40| `validateOn` | `GlassValidationTrigger` | `.afterEditing` | When the message starts to show. |41| `errorMessage` | `String?` | `nil` | External error. |4243## States4445Hidden (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.4647## Advanced example4849```swift50GlassSecureField(51    "New password", text: $password,52    helper: "At least 12 characters.",53    content: .newPassword,54    allowsReveal: true,55    validation: GlassFieldValidation(.required(), .minLength(12)),56    errorMessage: model.passwordError57)58.onSubmit { model.changePassword(to: password) }59```6061## Accessibility6263- The reveal button is labelled with the action it performs: "Show password", then "Hide password" (localised).64- The button has the platform's minimum hit target and is reachable with the keyboard.65- Errors are an icon and a sentence, not colour alone.66- The field is marked `privacySensitive()`, so the system can redact it where it redacts private content.6768## Limits6970- The component never logs, stores or copies the content; what the host does with the binding is its own responsibility.71- Revealing swaps the secure field for a plain one; the focus is handed over in code, but the caret position is not kept.72- GlassKit cannot prevent screen recording or screenshots.73- AutoFill, strong password suggestions and the focus hand-over were not exercised on a running device here.74
Files main
Menu

Theme