SP GlassKit1.1.0

GlassTextField

Text field with label, validation message, focus handling and keyboard configuration.

  • Content
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-text-field

Content on an opaque, readable surface. Glass is kept for controls.

GlassTextField running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-text-field

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-text-field
ModuleSPGlassForms
Kindcontent-component — a system TextField on an opaque themed surface with glassFieldOutline
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Forms/GlassTextFieldExample.swift

Minimal usage

Swift
@State private var name = ""

GlassTextField("Name", text: $name)

Variants

VariantUse
prompt:Placeholder shown while the field is empty.
helper:Explanation under the field, replaced by the error when there is one.
validation:Rules checked in order: .required(), .minLength(_:), .maxLength(_:), .custom(message:_:).
validateOn:.afterEditing (default: once the field was left or submitted), .always, .never.
errorMessage:An error decided by the host (server answer). It replaces the validation message.
systemImage:An SF Symbol at the leading edge of the field ("envelope", "at"); it takes the primary colour while the field is focused.
successMessage:A confirmation decided by the host ("This name is available."): success outline, check mark in the field and the sentence under it.
input:.standard, .email, .username, .url, .number, .name, or a custom GlassTextInputConfiguration.

Parameters

ParameterTypeDefaultMeaning
labelLocalizedStringKey—Label above the field; also its accessibility label.
textBinding<String>—The value.
promptLocalizedStringKey?nilPlaceholder.
helperLocalizedStringKey?nilHelper text.
validationGlassFieldValidation.noneRules of the field.
validateOnGlassValidationTrigger.afterEditingWhen the message starts to show.
systemImageString?nilLeading SF Symbol, decorative (1.1).
errorMessageString?nilExternal error.
successMessageString?nilConfirmation, already localised; shown when there is no error (1.1).
inputGlassTextInputConfiguration.standardAutocorrection, capitalisation, keyboard, content type.
focusFocusState<Bool>.Binding?nilFocus owned by the host.

GlassTextInputConfiguration holds autocorrectionDisabled, capitalization, keyboard and contentKind. Capitalisation and keyboard apply on iOS and iPadOS only.

States

Idle (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".

Advanced example

Swift
@State private var email = ""
@State private var serverError: String?
@FocusState private var emailFocused: Bool

GlassTextField(
    "Email", text: $email, prompt: "name@example.com",
    validation: GlassFieldValidation(
        .required(),
        .custom(message: String(localized: "Enter a valid address")) { $0.contains("@") }
    ),
    errorMessage: serverError,
    input: .email,
    focus: $emailFocused
)
.submitLabel(.next)
.onSubmit { register() }

The rules are pure and can be checked before submitting: validation.isValid(email).

Accessibility

  • The visible label is the accessibility label of the field; "Required" is appended for required fields.
  • An error is an icon plus a sentence, read as "Error: …"; a confirmation is a check mark plus a sentence. Neither is colour alone.
  • The leading symbol is decorative and hidden from VoiceOver.
  • Label, value and messages follow Dynamic Type and wrap.
  • Default messages are localised (English, French); lengths count user-perceived characters.

Limits

  • Single line; use GlassTextArea for multiline text.
  • Validation is synchronous. Asynchronous checks (availability of a name) go through errorMessage.
  • Length and custom rules accept an empty value; add .required() to refuse it.
  • On macOS, capitalisation and keyboard settings have no effect, and only some content types exist.
  • Focus changes and the keyboard were not exercised on a running device here.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassTextFieldExample: GlassExample {
    public static let componentID = "glass-text-field"
    @State private var name = ""
    @State private var email = ""
    @State private var handle = "taken"
    @State private var locked = "Read-only value"
    @FocusState private var emailFocused: Bool

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 20) {
                GlassTextField(
                    "Full name",
                    text: $name,
                    prompt: "Ada Lovelace",
                    validation: GlassFieldValidation(.required(), .minLength(2)),
                    input: .name
                )
                .onSubmit { emailFocused = true }

                GlassTextField(
                    "Email",
                    text: $email,
                    prompt: "name@example.com",
                    helper: "Used only for the receipt.",
                    systemImage: "envelope",
                    validation: GlassFieldValidation(.required(), .custom(message: "Enter an address such as name@example.com") { $0.contains("@") && $0.contains(".") }),
                    input: .email,
                    focus: $emailFocused
                )

                GlassTextField(
                    "Username",
                    text: $handle,
                    validation: GlassFieldValidation(.maxLength(12)),
                    validateOn: .always,
                    errorMessage: handle == "taken" ? "This username is already taken." : nil,
                    input: .username
                )

                GlassTextField("Account", text: $locked)
                    .disabled(true)

                Button("Focus the email field") { emailFocused = true }
            }
            .padding()
        }
    }
}

#Preview("GlassTextField") { GlassTextFieldExample().glassTheme(.aurora) }

Registry entry

Identifierglass-text-field
Version1.1.0
Depends onglass-forms-support, glass-foundation
FrameworksSwiftUI
Public symbolsGlassTextField
LicenceMIT
Manifestmanifest.json

Files