[Submitted as FB25597038]
Showing the sidebar in a two-column NavigationSplitView briefly collapses the toolbar search field, even though the window doesn't resize. Search is right-aligned on the detail container using .searchable, ToolbarSpacer(.flexible), and DefaultToolbarItem(kind: .search).
The sample below uses static content and the native sidebar toggle and animation. Setting only the sidebar item's collapseBehavior to .useConstraints avoids the issue. It occurred in both recorded baseline expansions and neither expansion with the workaround.
- macOS 27.2.1 (26B131)
- Xcode 27.2 (27B52)
- macOS SDK 27.2 (26B118)
- Native macOS app, arm64, deployment target macOS 27.0
- Initial window: 906 × 600 points
- Sidebar minimum/ideal/maximum widths: 180/240/360 points
- Create a new macOS App project named
SidebarAnimationRepro, using SwiftUI and Swift. Set the deployment target to macOS 27.0. - Replace
SidebarAnimationReproApp.swiftandContentView.swiftwith the code below. LeaveusesWorkaroundset tofalse. - Build and run. Keep the initial 906-point window width.
- Click Hide Sidebar and let the transition settle.
- Click Show Sidebar and watch the search field during expansion.
- Stop the app, change
usesWorkaroundtotrue, and run again. Repeat steps 4–5 to compare the behavior.
The split view should stay within the window during sidebar expansion. The search field should stay visible at its normal width without briefly collapsing or disappearing.
The split view temporarily grows to 1,146 points while the window stays 906 points wide. Search shrinks from 325 to 36 points and disappears, then returns to its normal size and visibility. The toolbar, search item, and search field remain the same instances, and toolbar item order doesn't change.
In one capture, search collapsed about 123 ms after expansion started, returned at 274 ms, and the split view settled at 283 ms.
With .useConstraints, the split view stayed at 906 points and search stayed visible at 325 points throughout both hide/show cycles.
Three frames before, during, and after the sidebar expansion:
SidebarAnimationReproApp.swift
import SwiftUI
@main
struct SidebarAnimationReproApp: App {
var body: some Scene {
WindowGroup("Sidebar Animation Repro") {
ContentView()
}
.defaultSize(width: 906, height: 600)
}
}
ContentView.swift
import AppKit
import SwiftUI
struct ContentView: View {
@State private var searchText = ""
var body: some View {
NavigationSplitView {
List {
Label("Example", systemImage: "folder")
}
.navigationSplitViewColumnWidth(min: 180, ideal: 240, max: 360)
} detail: {
Text("Synthetic detail content")
.frame(minWidth: 0, maxWidth: .infinity, maxHeight: .infinity)
.background { SplitViewAttachment() }
.searchable(text: $searchText, placement: .toolbar)
.toolbar {
ToolbarSpacer(.flexible)
DefaultToolbarItem(kind: .search)
}
}
.toolbar(removing: .title)
.frame(minWidth: 720, minHeight: 420)
}
}
struct SplitViewAttachment: NSViewRepresentable {
func makeNSView(context: Context) -> Attachment { Attachment() }
func updateNSView(_ view: Attachment, context: Context) {
view.applyWorkaround()
}
final class Attachment: NSView {
private let usesWorkaround = false
override func hitTest(_ point: NSPoint) -> NSView? { nil }
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
applyWorkaround()
}
/// The split controller can enter the responder chain after the view enters its window.
override func layout() {
super.layout()
applyWorkaround()
}
fileprivate func applyWorkaround() {
guard usesWorkaround, window != nil else { return }
let responders = sequence(first: self as NSResponder, next: \.nextResponder)
guard let controller = responders.first(where: { $0 is NSSplitViewController }) as? NSSplitViewController,
let sidebar = controller.splitViewItems.first(where: { $0.behavior == .sidebar }),
sidebar.collapseBehavior != .useConstraints else { return }
sidebar.collapseBehavior = .useConstraints
}
}
}