[SOLVED] SwiftUI – How to disable sidebar from collapsing?


Gif to understand easier

Is there any way to disable collapsibility of SidebarListStyle NavigationViews?


Using this SwiftUI Introspection library:

We can introspect the underlying NSSplitView by extending their functionality:

public func introspectSplitView(customize: @escaping (NSSplitView) -> ()) -> some View {
    return introspect(selector: TargetViewSelector.ancestorOrSibling, customize: customize)

And then create a generic extension on View:

public extension View {
    func preventSidebarCollapse() -> some View {
        return introspectSplitView { splitView in
            (splitView.delegate as? NSSplitViewController)?.splitViewItems.first?.canCollapse = false

Which can be used on our sidebar:

var body: some View {

Answered By – Oskar

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *