Skip to content

Commit e6bb1e1

Browse files
author
Jannik Weise
committed
🐛 Fix check for click handlers to also return true if checkbox is given
Ensures that click handlers within Checkbox components are properly detected within the accordion component to prevent accidental accordion toggling.
1 parent 0899226 commit e6bb1e1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/core/src/utils/accordion.ts

+10
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,23 @@ export const getElementClickEvent = (element: ReactNode) => {
5252
const checkForClickHandler = (el: ReactNode) => {
5353
if (!isValidElement(el)) return;
5454

55+
// @ts-expect-error: Difficult to type
56+
if ('displayName' in el.type && el.type.displayName === 'Checkbox') {
57+
hasClickHandler = true;
58+
59+
return;
60+
}
61+
62+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5563
if (el.props.onClick) {
5664
hasClickHandler = true;
5765

5866
return;
5967
}
6068

69+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6170
if (el.props.children) {
71+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
6272
Children.forEach(el.props.children, checkForClickHandler);
6373
}
6474
};

0 commit comments

Comments
 (0)