SPB Git

Repository Public MIT

glass-split-button.md 2.5 KB 72 lines markdown

1# GlassSplitButton23| | |4|---|---|5| Identifier | `glass-split-button` |6| Module | `SPGlassComponents` |7| Kind | `native-wrapper` — `Menu` with a primary action on macOS; a glass button and a glass menu button on iOS and iPadOS |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Buttons/GlassSplitButtonExample.swift` |1011## Minimal usage1213```swift14GlassSplitButton("Send", systemImage: "paperplane") {15    send()16} menu: {17    Button("Send later…") { schedule() }18    Button("Save draft") { saveDraft() }19}20```2122## Variants2324| Platform | Form |25|---|---|26| macOS | The system split button: `Menu(content:label:primaryAction:)`. |27| iOS, iPadOS | Two glass buttons in one glass container: the action, and a circular menu button. Each is its own accessibility element and hit target. |2829`variant` and `size` behave as for `GlassButton`.3031## Parameters3233| Parameter | Type | Default | Meaning |34|---|---|---|---|35| `titleKey` | `LocalizedStringKey` | — | Title of the primary action. |36| `systemImage` | `String?` | `nil` | SF Symbol of the primary action. |37| `variant` | `GlassButtonVariant` | `.regular` | Visual weight of both parts. |38| `size` | `GlassControlSize` | `.regular` | Control size. |39| `menuAccessibilityLabel` | `LocalizedStringKey?` | "More actions" (localised) | Name of the menu part. |40| `action` | `@MainActor () -> Void` | — | Primary action. |41| `menu` | `@ViewBuilder` | — | Menu content: buttons, sections, dividers. |4243## States4445Pressed, focused and menu-open states are drawn by the system. Disable the whole control with `.disabled(_:)`; disable single menu items on the items themselves.4647## Advanced example4849```swift50GlassSplitButton("Export", systemImage: "square.and.arrow.up", variant: .prominent, menuAccessibilityLabel: "Export options") {51    export(.pdf)52} menu: {53    Section("Format") {54        Button("PDF") { export(.pdf) }55        Button("PNG") { export(.png) }56    }57    Button("Export settings…") { showSettings() }58}59```6061## Accessibility6263- The action and the menu are two separate, labelled elements on iOS and iPadOS.64- The menu part has its own name, "More actions" by default, in English and French.65- Both parts meet the minimum hit target.66- Menu items are standard buttons: VoiceOver, keyboard and Switch Control work as in any system menu.6768## Limits6970- On macOS the appearance is the system's split button and does not use a separate circular menu button.71- Put the most frequent action first: the menu is for alternatives, not for the main path.72
Files main
Menu

Theme