Skip to content

Commit eedb9f8

Browse files
fix(Avatar): Don't crash onClick when no handler is passed (#276)
Fixes #272
1 parent b403bdc commit eedb9f8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/main/src/components/Avatar/Avatar.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describe('Avatar', () => {
5959
expect(callback.called).toBe(true);
6060
});
6161

62+
test('do not crash onClick w/o handler (#272)', () => {
63+
expect(() => {
64+
const wrapper = mountThemedComponent(<Avatar size={AvatarSize.XL} initials="JD" />);
65+
wrapper.find(Avatar).simulate('click');
66+
}).not.toThrow();
67+
});
68+
6269
test('enter key down', () => {
6370
const callback = sinon.spy();
6471
const wrapper = mountThemedComponent(<Avatar size={AvatarSize.XL} initials="JD" onClick={callback} />);

packages/main/src/components/Avatar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ const Avatar: FC<AvatarPropTypes> = forwardRef((props: AvatarPropTypes, ref: Ref
7676
const handleKeyDown = useCallback(
7777
(e) => {
7878
if (e.key === 'Enter') {
79-
onClick(Event.of(null, e));
79+
onClick?.(Event.of(null, e));
8080
}
8181
},
8282
[onClick]
8383
);
8484

8585
const handleOnClick = useCallback(
8686
(e) => {
87-
onClick(Event.of(null, e));
87+
onClick?.(Event.of(null, e));
8888
},
8989
[onClick]
9090
);

0 commit comments

Comments
 (0)