File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -143,9 +143,8 @@ export function getRole(element: ReactTestInstance): Role | AccessibilityRole {
143
143
return 'text' ;
144
144
}
145
145
146
- if ( isHostImage ( element ) && element . props . alt ) {
147
- return 'img' ;
148
- }
146
+ // Note: host Image elements report "image" role in screen reader only on Android, but not on iOS.
147
+ // It's better to require explicit role for Image elements.
149
148
150
149
return 'none' ;
151
150
}
Original file line number Diff line number Diff line change @@ -227,12 +227,22 @@ describe('supports name option', () => {
227
227
} ) ;
228
228
229
229
test ( 'supports host Image element with "alt" prop' , ( ) => {
230
- render ( < Image alt = "An elephant" testID = "image" /> ) ;
230
+ render (
231
+ < >
232
+ < Image testID = "image1" role = "img" alt = "an elephant" />
233
+ < Image testID = "image2" accessibilityRole = "image" alt = "a tiger" />
234
+ </ > ,
235
+ ) ;
236
+
237
+ const expectedElement1 = screen . getByTestId ( 'image1' ) ;
238
+ expect ( screen . getByRole ( 'img' , { name : 'an elephant' } ) ) . toBe ( expectedElement1 ) ;
239
+ expect ( screen . getByRole ( 'image' , { name : 'an elephant' } ) ) . toBe ( expectedElement1 ) ;
240
+ expect ( screen . getByRole ( / i m g / , { name : / e l e p h a n t / } ) ) . toBe ( expectedElement1 ) ;
231
241
232
- const expectedElement = screen . getByTestId ( 'image ' ) ;
233
- expect ( screen . getByRole ( 'img' , { name : 'An elephant ' } ) ) . toBe ( expectedElement ) ;
234
- expect ( screen . getByRole ( 'image' , { name : 'An elephant ' } ) ) . toBe ( expectedElement ) ;
235
- expect ( screen . getByRole ( / i m g / , { name : 'An elephant' } ) ) . toBe ( expectedElement ) ;
242
+ const expectedElement2 = screen . getByTestId ( 'image2 ' ) ;
243
+ expect ( screen . getByRole ( 'img' , { name : 'a tiger ' } ) ) . toBe ( expectedElement2 ) ;
244
+ expect ( screen . getByRole ( 'image' , { name : 'a tiger ' } ) ) . toBe ( expectedElement2 ) ;
245
+ expect ( screen . getByRole ( / i m g / , { name : / t i g e r / } ) ) . toBe ( expectedElement2 ) ;
236
246
} ) ;
237
247
} ) ;
238
248
You can’t perform that action at this time.
0 commit comments