I'm using a NSCollectionView
to layout custom views horizontally. Each NSCollectionViewItem
hosts a custom NSView
that acts like a checkbox. These custom child views support accessibility on their own (by overriding the required accessibility methods, such as accessibilityRole
, accessibilityLabel
and so on).
I cannot, however, seem to be able to promote these custom views to become the primary UI view so that they're accessible directly. When I inspect using Accessibility Inspector, each collection view item appears to be a Group
and there seems to be no way to automate pressing of a button, for example, since the custom view isn't visible to it.
I tried implementing NSAccessibilityButton
on the collection view item, however I don't know what to return for accessibilityParent()
- it seems by default NSCollectionViewItem
s return the parent collection view section, but that's in-accessible without perhaps subclassing NSCollectionView and its layout.
The following did not help either:
public override var accessibilityFocusedUIElement: Any? {
return self.customView
}
This never gets called. The question is, how does one add support for accessibility when using a NSCollectionView
/ NSCollectionViewItem
? I simply wish to surface one of its child views so it becomes accessible to automator or apps such as keyboard maestro.
Not sure if this is a workaround or the only possible solution, but this is how I got it to work:
view
of aNSCollectionViewItem
in `loadView()Here's my proxy class: