Repository Public MIT
1# GlassTextField23| | |4|---|---|5| Identifier | `glass-text-field` |6| Module | `SPGlassForms` |7| Kind | `content-component` — a system `TextField` on an opaque themed surface with `glassFieldOutline` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Forms/GlassTextFieldExample.swift` |1011## Minimal usage1213```swift14@State private var name = ""1516GlassTextField("Name", text: $name)17```1819## Variants2021| Variant | Use |22|---|---|23| `prompt:` | Placeholder shown while the field is empty. |24| `helper:` | Explanation under the field, replaced by the error when there is one. |25| `validation:` | Rules checked in order: `.required()`, `.minLength(_:)`, `.maxLength(_:)`, `.custom(message:_:)`. |26| `validateOn:` | `.afterEditing` (default: once the field was left or submitted), `.always`, `.never`. |27| `errorMessage:` | An error decided by the host (server answer). It replaces the validation message. |28| `systemImage:` | An SF Symbol at the leading edge of the field (`"envelope"`, `"at"`); it takes the `primary` colour while the field is focused. |29| `successMessage:` | A confirmation decided by the host ("This name is available."): success outline, check mark in the field and the sentence under it. |30| `input:` | `.standard`, `.email`, `.username`, `.url`, `.number`, `.name`, or a custom `GlassTextInputConfiguration`. |3132## Parameters3334| Parameter | Type | Default | Meaning |35|---|---|---|---|36| `label` | `LocalizedStringKey` | — | Label above the field; also its accessibility label. |37| `text` | `Binding<String>` | — | The value. |38| `prompt` | `LocalizedStringKey?` | `nil` | Placeholder. |39| `helper` | `LocalizedStringKey?` | `nil` | Helper text. |40| `validation` | `GlassFieldValidation` | `.none` | Rules of the field. |41| `validateOn` | `GlassValidationTrigger` | `.afterEditing` | When the message starts to show. |42| `systemImage` | `String?` | `nil` | Leading SF Symbol, decorative (1.1). |43| `errorMessage` | `String?` | `nil` | External error. |44| `successMessage` | `String?` | `nil` | Confirmation, already localised; shown when there is no error (1.1). |45| `input` | `GlassTextInputConfiguration` | `.standard` | Autocorrection, capitalisation, keyboard, content type. |46| `focus` | `FocusState<Bool>.Binding?` | `nil` | Focus owned by the host. |4748`GlassTextInputConfiguration` holds `autocorrectionDisabled`, `capitalization`, `keyboard` and `contentKind`. Capitalisation and keyboard apply on iOS and iPadOS only.4950## States5152Idle (opaque `surface` with a hairline), focused (outline in the theme's `focusRing` colour plus a crisp outer ring), error (outline in `destructive`, a mark inside the field, icon and message under it), success (`successMessage`: outline in `success`, check mark, confirmation), disabled (`.disabled(_:)`, dimmed). A required field shows an asterisk next to its label and announces "Required".5354## Advanced example5556```swift57@State private var email = ""58@State private var serverError: String?59@FocusState private var emailFocused: Bool6061GlassTextField(62 "Email", text: $email, prompt: "name@example.com",63 validation: GlassFieldValidation(64 .required(),65 .custom(message: String(localized: "Enter a valid address")) { $0.contains("@") }66 ),67 errorMessage: serverError,68 input: .email,69 focus: $emailFocused70)71.submitLabel(.next)72.onSubmit { register() }73```7475The rules are pure and can be checked before submitting: `validation.isValid(email)`.7677## Accessibility7879- The visible label is the accessibility label of the field; "Required" is appended for required fields.80- An error is an icon plus a sentence, read as "Error: …"; a confirmation is a check mark plus a sentence. Neither is colour alone.81- The leading symbol is decorative and hidden from VoiceOver.82- Label, value and messages follow Dynamic Type and wrap.83- Default messages are localised (English, French); lengths count user-perceived characters.8485## Limits8687- Single line; use `GlassTextArea` for multiline text.88- Validation is synchronous. Asynchronous checks (availability of a name) go through `errorMessage`.89- Length and custom rules accept an empty value; add `.required()` to refuse it.90- On macOS, capitalisation and keyboard settings have no effect, and only some content types exist.91- Focus changes and the keyboard were not exercised on a running device here.92