Skip to content

Commit 47604cc

Browse files
committed
fix: prevent double-firing for button click aliases
1 parent abbec2d commit 47604cc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

site/src/components/CodeExample/CodeExample.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export const CodeExample: FC<CodeExampleProps> = ({
2323
}) => {
2424
const buttonRef = useRef<HTMLButtonElement>(null);
2525
const triggerButton = (event: KeyboardEvent | MouseEvent) => {
26-
if (event.target !== buttonRef.current) {
26+
const clickTriggeredOutsideButton =
27+
event.target instanceof HTMLElement &&
28+
!buttonRef.current?.contains(event.target);
29+
30+
if (clickTriggeredOutsideButton) {
2731
buttonRef.current?.click();
2832
}
2933
};

0 commit comments

Comments
 (0)