I'm trying to hide several elements in my app from VoiceOver so that they don't get read aloud by the screen reader. On iOS, I'd set isAccessibilityElement
to NO
, but this has no effect on OSX. What's the correct way to go about hiding elements from VoiceOver?
For example, I have a series of labels contained inside a view that make no sense if they're spoken separately by VoiceOver. I'd like to set the accessibilityLabel
on the container view to describe all the labels nested within. But if I do that, the labels inside are still read out by VoiceOver.
The main reason the visibility: hidden rule isn't just about visual visibility is because it affects the elements visibility to assistive technology as well. When we apply visibility: hidden to an element, it also removes it from the accessibility tree, which makes it invisible to technologies like screen readers.
The conventional way is to use CSS ( display:none; and visibility:hidden; ) or the HTML 5 `hidden` attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).
Open your Android device's Settings app . Select Accessibility. Switch Access. At the top, select the On/Off switch.
To hide text from a screen reader and display it visually, use the aria-hidden attribute and set it to true. To hide text from a screen reader and hide it visually use the hidden attribute. You can also use CSS to set display: none or visibility: hidden to hide an element from screen readers and visually.
In macOS, it is true that setting accessibilityElement
to NO
for NSButton
, NSTextField
and NSImageView
has no effect. That is because these are controls – they inherit from NSControl
. To make it work for controls, you must do it instead to the control's cell.
In an Objective-C project, I so subclassed several Cocoa controls. For example, whenever I want a image view to be skipped by VoiceOver, I set its Custom Class in Interface Builder to this:
/*!
@brief Image view which will be skipped over by VoiceOver
@details Be careful that you *really* want the view to be skipped over by
VoiceOver, because its meaning is conveyed in a better, non-visual way,
elsewhere. Remember that not all VoiceOver users are completely blind.
*/
@interface SSYNoVoiceOverImageView : NSImageView {}
@end
@implementation SSYNoVoiceOverImageView
- (void)awakeFromNib {
self.cell.accessibilityElement = NO;
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With