SPB Git

Repository Public MIT

doc-glass-text-area.md 3.0 KB 74 lines markdown

1# GlassTextArea23| | |4|---|---|5| Identifier | `glass-text-area` |6| Module | `SPGlassForms` |7| Kind | `content-component` — a system `TextEditor` on an opaque themed surface |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Forms/GlassTextAreaExample.swift` |1011## Minimal usage1213```swift14@State private var notes = ""1516GlassTextArea("Notes", text: $notes)17```1819## Variants2021| Variant | Use |22|---|---|23| `placeholder:` | Text shown while the editor is empty. |24| `limit:` | Largest number of characters; extra input is dropped and the counter appears. |25| `showsCounter: true` | A counter without a limit ("42"). |26| `helper:` / `errorMessage:` | Text under the editor; the error replaces the helper. |27| `minHeight:` | Smallest height at the default text size; it scales with Dynamic Type. |2829## Parameters3031| Parameter | Type | Default | Meaning |32|---|---|---|---|33| `label` | `LocalizedStringKey` | — | Label above the editor; also its accessibility label. |34| `text` | `Binding<String>` | — | The value. |35| `placeholder` | `String?` | `nil` | Placeholder, already localised. |36| `helper` | `LocalizedStringKey?` | `nil` | Helper text. |37| `limit` | `Int?` | `nil` | Character limit. |38| `showsCounter` | `Bool?` | `nil` | Counter visibility; `nil` shows it when there is a limit. |39| `minHeight` | `CGFloat` | `96` | Minimum height before Dynamic Type scaling. |40| `errorMessage` | `String?` | `nil` | External error. |4142## States4344Empty (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".4546## Advanced example4748```swift49GlassTextArea(50    "Review", text: $review,51    placeholder: String(localized: "What did you think of your stay?"),52    helper: "Visible to everyone.",53    limit: 500,54    minHeight: 140,55    errorMessage: review.count < 20 && didSubmit ? String(localized: "Write at least 20 characters.") : nil56)57```5859Counting and clamping are public and pure: `GlassTextLimit.clamp("a👨‍👩‍👧‍👦b", to: 2)` gives `"a👨‍👩‍👧‍👦"`.6061## Accessibility6263- 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.64- The limit counts user-perceived characters: an emoji, a flag or an accented letter counts as one and is never cut in two.65- The counter has a spoken form with words, and digits follow the locale.66- The minimum height grows with the text size; the editor scrolls inside it.6768## Limits6970- Plain text only (`String`); no rich text or attachments.71- The limit is applied after the system inserted the text, so an over-long paste appears and is cut in the same update.72- 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.73- Scrolling, selection and the keyboard are the system's; they were not exercised on a running device here.74
Files main
Menu

Theme