GlassPanel
| Identifier | glass-panel |
| Module | SPGlassComponents |
| Kind | custom-glass — one glassSurface; the controls inside are plain system controls |
| Platforms | iOS 26, iPadOS 26, macOS 26 (resizing and focus scope on macOS only) |
| Example | Examples/Gallery/Containers/GlassPanelExample.swift |
Minimal usage
swift
GlassPanel("Layers") {
Toggle("Transit", isOn: $showsTransit)
}Variants
| Variant | Use |
|---|---|
| Fixed | No size: the panel takes the size of its content. |
| Resizable (macOS) | size: $panelSize: a handle in the trailing-bottom corner resizes within sizeLimits. |
| Closable | onClose: adds a close button; Escape calls it. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title |
LocalizedStringKey or Text |
— | Heading and accessibility label of the panel. |
size |
Binding<CGSize>? |
nil |
Controlled size on macOS. Ignored on iOS and iPadOS. |
sizeLimits |
GlassPanelSizeLimits |
.standard (240 × 160 to 720 × 640) |
Bounds applied to size. |
onClose |
(@MainActor () -> Void)? |
nil |
Shows the close button and handles Escape. |
content |
@ViewBuilder |
— | Controls of the panel. |
GlassPanelSizeLimits.clamp(_:) and resized(from:translation:isRightToLeft:) are pure and can be reused by the host, for example to restore a saved size.
States
The panel itself has no state. The host decides whether it is shown; size is the host's state. While the handle is dragged the size follows the pointer immediately, without animation.
Advanced example
swift
@State private var size = CGSize(width: 320, height: 240)
let limits = GlassPanelSizeLimits(minimum: CGSize(width: 260, height: 180), maximum: CGSize(width: 520, height: 420))
GlassPanel("Inspector", size: $size, sizeLimits: limits, onClose: { showsInspector = false }) {
Picker("Blend", selection: $blend) { ForEach(Blend.allCases) { Text($0.name).tag($0) } }
Slider(value: $opacity, in: 0...1) { Text("Opacity") }
}
.onChange(of: size) { _, new in settings.inspectorSize = limits.clamp(new) }Accessibility
- The panel is an accessibility container named by its title; the title has the header trait.
- The close button is labelled "Close" (localised) and has the minimum hit target.
- macOS: the panel is a focus scope and a focus section, so Tab and arrow keys move among its controls as a group. Escape calls
onClosewhile focus is inside the panel. - iOS and iPadOS with a hardware keyboard: Escape triggers the close button (
.keyboardShortcut(.cancelAction)). - The resize handle is focusable (arrow keys resize by one spacing step), is announced as "Resize panel" with the current size as its value, and supports the VoiceOver adjustable action.
- With Reduce Transparency the surface is opaque (handled by
glassSurface).
Limits
- The panel does not move itself: place it with
overlay,safeAreaInsetor your own drag logic. - Resizing exists on macOS only; on iPadOS use a sheet with detents or
GlassMapPanelfor an extensible panel. - Keep the content to controls and short labels; long or dense content belongs in an opaque
GlassCard. - Do not put glass buttons (
GlassButton) inside the panel: glass must not sit inside glass. Use plain or bordered system buttons. - The behaviour of focus and Escape was compiled but not exercised in a running application by the automated tests.