Hide sidebar in a split view programmatically in SwiftUI

I have a split view (master-detail) on iPad. The sidebar contains a VStack of buttons and I would like to be able to close it when any of the buttons are touched.

The implementation is in SwiftUI and I use NavigationView to be compatible with older versions of iOS. I don't use NavigationSplitView because it requires iOS 16 or later.

I can't find documentation about it and I don't want to use external libraries.

Hide sidebar in a split view programmatically in SwiftUI
 
 
Q