Skip to content

Commit 1181dc8

Browse files
suezzothymikee
authored andcommitted
feat: add pointerEvents box-none handling
1 parent 076b8a5 commit 1181dc8

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/__tests__/fireEvent.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,21 @@ test('should not fire on box-only pointerEvents View', () => {
264264
expect(handlePress).not.toHaveBeenCalled();
265265
});
266266

267+
test('should fire on box-none pointerEvents View', () => {
268+
const handlePress = jest.fn();
269+
270+
const screen = render(
271+
<View pointerEvents="box-none">
272+
<Pressable onPress={handlePress}>
273+
<Text>Trigger</Text>
274+
</Pressable>
275+
</View>
276+
);
277+
278+
fireEvent.press(screen.getByText('Trigger'));
279+
expect(handlePress).toHaveBeenCalled();
280+
});
281+
267282
test('should not fire on none pointerEvents View with nested elements', () => {
268283
const handlePress = jest.fn();
269284

src/fireEvent.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ const isTouchResponder = (element?: ReactTestInstance) => {
1717
return !!element?.props.onStartShouldSetResponder || isTextInput(element);
1818
};
1919

20-
const isPointerEventEnabled = (element?: ReactTestInstance) => {
21-
if (
22-
element?.props.pointerEvents === 'none' ||
23-
element?.props.pointerEvents === 'box-only'
24-
) {
20+
const isPointerEventEnabled = (
21+
element?: ReactTestInstance,
22+
isParent?: boolean
23+
) => {
24+
const parentCondition = isParent
25+
? element?.props.pointerEvents === 'box-only'
26+
: element?.props.pointerEvents === 'box-none';
27+
28+
if (element?.props.pointerEvents === 'none' || parentCondition) {
2529
return false;
2630
}
2731

2832
if (!element?.parent) return true;
2933

30-
return isPointerEventEnabled(element.parent);
34+
return isPointerEventEnabled(element.parent, true);
3135
};
3236

3337
const isEventEnabled = (

0 commit comments

Comments
 (0)