NSHostingView doesn't work when used as an accessory view for NSOpenPanel

Our app presents an NSOpenPanel with an accessory view implemented in SwiftUI and presented via NSHostingView. TextFields and pickers are working OK, but Buttons and Toggles (checkboxes) aren’t, although Toggles styled with .switch are functioning as expected. Specifically:

  1. Toggles styled with .checkbox fail with no feedback. Overriding NSHostingView mouseDown() shows that the mouse event is completely ignored by the Toggle
  2. Buttons “see” the mouseDown event (the button highlights when pressed, and the event doesn’t fall through to the hosting view), but the button action isn’t triggered until the dialog is dismissed

Any idea on how to get these controls functional?

Answered by DTS Engineer in 825762022

@okaywhatever Thanks for flagging this. That looks like a bug to me. Can you please file a Bug report via Feedback assistant and Post the Feedback ID number here for the record.

Could you please provide a code snippet of your implementation or share a small text project that demonstrates the issue.

If you're not familiar with preparing a test project, take a look at Creating a test project.

Here's the reproduction project:

https://github.com/eidria/AccessoryViewTest.git

Run the app in the debugger. When the window appears, you will see the accessory view presented inside the Content view. You can verify that all the controls function as expected, and that the App Model gets updated as intended. Now, click the button that shows the same view as an accessory view in a NSOpenPanel.

Notice:

  1. The Text Field, Picker and Toggle configured as a switch all work as intended. The checkbox and button do not.
  2. If you clicked the button, notice that the button highlights when pressed, but the action takes place when the dialog is dismissed either through cancel or OK.

Why aren’t checkboxes and buttons working in Accessory views? What can I do to get them to work?

Accepted Answer

@okaywhatever Thanks for flagging this. That looks like a bug to me. Can you please file a Bug report via Feedback assistant and Post the Feedback ID number here for the record.

Here's the Feedback ID FB16536195.

NSHostingView doesn't work when used as an accessory view for NSOpenPanel
 
 
Q