Skip to content

Add support for pointerEvents #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Trancever opened this issue Jan 8, 2021 · 1 comment · Fixed by #655
Closed

Add support for pointerEvents #650

Trancever opened this issue Jan 8, 2021 · 1 comment · Fixed by #655

Comments

@Trancever
Copy link
Contributor

Trancever commented Jan 8, 2021

Describe the Feature

Currently, when there is a wrapping View with pointerEvents="none" testing lib still allows pressing buttons that are rendered inside of that View.

Expected behaviour:

// component
<View pointerEvents="none">
  <Touchable onPress={onPress}>Click me</Touchable>
</View>

...

// test
const mockOnPress = jest.fn();
const { getByText } = render(<Component onPress={mockOnPress} />);

fireEvent.press(getByText('Click me'));

expect(mockOnPress).not.toHaveBeenCalled();

Possible Implementations

No idea, cause I am not familiar with the codebase :(

Related Issues

@thymikee
Copy link
Member

thymikee commented Jan 8, 2021

Yup, that's a fair call to make. Needs adjustments in fireEvent implementation:

const findEventHandler = (
element: ReactTestInstance,
eventName: string,
callsite?: any,
nearestTouchResponder?: ReactTestInstance,
hasDescendandHandler?: boolean
) => {
const touchResponder = isTouchResponder(element)
? element
: nearestTouchResponder;
const handler = getEventHandler(element, eventName);
if (handler && isEventEnabled(element, touchResponder)) return handler;
// Do not bubble event to the root element
const hasHandler = handler != null || hasDescendandHandler;
if (element.parent === null || element.parent.parent === null) {
if (hasHandler) {
return null;
} else {
throw new ErrorWithStack(
`No handler function found for event: "${eventName}"`,
callsite || invokeEvent
);
}
}
return findEventHandler(
element.parent,
eventName,
callsite,
touchResponder,
hasHandler
);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants