Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Jan 23, 2025
1 parent 34e0760 commit c275b91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/internal/primitives/DismissableLayer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,18 @@ describe('DismissableLayer', () => {
fireEvent.pointerDown(document.body);
expect(onDismiss).not.toHaveBeenCalled();
});

it('handles null event target gracefully', () => {
render(
<DismissableLayer onDismiss={onDismiss}>
<div>Test Content</div>
</DismissableLayer>,
);

const event = new Event('pointerdown', { bubbles: true });
Object.defineProperty(event, 'target', { value: null });
document.dispatchEvent(event);

expect(onDismiss).not.toHaveBeenCalled();
});
});
4 changes: 4 additions & 0 deletions src/internal/primitives/DismissableLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function DismissableLayer({
return;
}

if (!event.target) {
return;
}

const target = event.target as Node;

if (triggerRef?.current?.contains(target)) {
Expand Down

0 comments on commit c275b91

Please sign in to comment.