Closed as not planned
Description
Describe the bug
We have a problem when querying nested touchables, see the example for more details:
describe('nested touchables', () => {
it('conflicting elements', () => {
const { getByRole } = render(
<Pressable accessibilityRole="button">
<Text>Some other text</Text>
<Pressable accessibilityRole="button">
<Text>Save</Text>
</Pressable>
</Pressable>
);
// Found multiple elements with accessibilityRole: button
// Here I'm not sure what we should do. This is not an accessible pattern.
// At least we should suggest a better error (might be just a warning/error on nested touchables)
expect(getByRole('button', { name: 'Save' })).toBeTruthy();
});
it('with accessible={false}', () => {
const { getByRole } = render(
<Pressable accessibilityRole="button" accessible={false}>
<Text>Some other text</Text>
<Pressable accessibilityRole="button">
<Text>Save</Text>
</Pressable>
</Pressable>
);
// Found multiple elements with accessibilityRole: button
// Here it should work and only getting the lower Pressable.
// `accessible={false}` means it won't be read to the screen-reader.
// This is a common pattern I've seen where you make a whole area implicitly touchable for better UX
// but add a nested explicit button for better discoverability (and accessibility)
expect(getByRole('button', { name: 'Save' })).toBeTruthy();
});
});
Versions
RNTL 11.2