GlassTextArea
Multiline editor with an accessible placeholder, optional limit and counter.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-text-area
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-text-areaCopies 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-text-area |
|---|---|
| Module | SPGlassForms |
| Kind | content-component — a system TextEditor on an opaque themed surface |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Forms/GlassTextAreaExample.swift |
Minimal usage
@State private var notes = ""
GlassTextArea("Notes", text: $notes)Variants
| Variant | Use |
|---|---|
placeholder: | Text shown while the editor is empty. |
limit: | Largest number of characters; extra input is dropped and the counter appears. |
showsCounter: true | A counter without a limit ("42"). |
helper: / errorMessage: | Text under the editor; the error replaces the helper. |
minHeight: | Smallest height at the default text size; it scales with Dynamic Type. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
label | LocalizedStringKey | — | Label above the editor; also its accessibility label. |
text | Binding<String> | — | The value. |
placeholder | String? | nil | Placeholder, already localised. |
helper | LocalizedStringKey? | nil | Helper text. |
limit | Int? | nil | Character limit. |
showsCounter | Bool? | nil | Counter visibility; nil shows it when there is a limit. |
minHeight | CGFloat | 96 | Minimum height before Dynamic Type scaling. |
errorMessage | String? | nil | External error. |
States
Empty (placeholder), focused (outline), at the limit (counter in the warning colour, the numbers themselves say so), error, disabled. The counter reads "12/280"; VoiceOver hears "12 of 280 characters".
Advanced example
GlassTextArea(
"Review", text: $review,
placeholder: String(localized: "What did you think of your stay?"),
helper: "Visible to everyone.",
limit: 500,
minHeight: 140,
errorMessage: review.count < 20 && didSubmit ? String(localized: "Write at least 20 characters.") : nil
)Counting and clamping are public and pure: GlassTextLimit.clamp("a👨👩👧👦b", to: 2) gives "a👨👩👧👦".
Accessibility
- The label is the accessibility label of the editor. While it is empty, the placeholder is read as its value; the painted placeholder itself is hidden from assistive technologies.
- The limit counts user-perceived characters: an emoji, a flag or an accented letter counts as one and is never cut in two.
- The counter has a spoken form with words, and digits follow the locale.
- The minimum height grows with the text size; the editor scrolls inside it.
Limits
- Plain text only (
String); no rich text or attachments. - The limit is applied after the system inserted the text, so an over-long paste appears and is cut in the same update.
- The placeholder is aligned with the first line by per-platform insets, which may drift by a point if the system changes the editor's padding.
- Scrolling, selection and the keyboard are the system's; they were not exercised on a running device here.
Example
import SwiftUI
import SPGlassKit
public struct GlassTextAreaExample: GlassExample {
public static let componentID = "glass-text-area"
@State private var notes = ""
@State private var bio = "Hiking 🥾, bread 🍞 and old maps 🗺️."
@State private var feedback = "Too short"
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
GlassTextArea("Notes", text: $notes, placeholder: "Anything the team should know before the visit", helper: "Visible to your team only.")
GlassTextArea("Short bio", text: $bio, limit: 40)
GlassTextArea(
"Feedback",
text: $feedback,
showsCounter: true,
minHeight: 72,
errorMessage: feedback.count < 20 ? "Please write at least 20 characters." : nil
)
GlassTextArea("Archived comment", text: .constant("This comment can no longer be edited."))
.disabled(true)
}
.padding()
}
}
}
#Preview("GlassTextArea") { GlassTextAreaExample().glassTheme(.solar) }
Registry entry
| Identifier | glass-text-area |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-forms-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassTextLimit, GlassTextArea |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Forms/GlassTextArea.swift7833 bytes · sha256 67557315d95d…